locked
Forcing cmdlets to run on a specific Domain Controller server RRS feed

  • Question

  • I have script that used the following cmdlets:

    • New-DistributionGroup
    • Set-DistributionGroup
    • Set-ADGroup
    • New-MailContact
    • Set-MailContact
    • Add-DistributionGroupMember

    I also have a section of code like this:

    $Contact = [ADSI]"LDAP://cn=$contactName,ou=Contacts,dc=contoso,dc=com"
    $Contact.description = "Requested by $owner"
    $Contact.SetInfo()

    And another like this:

    $DL = [ADSI]"LDAP://cn=$newDLName,ou=Distribution,dc=contoso,dc=com"
    $DL.Notes = "Requested by $owner"
    $DL.SetInfo()

    How do I force each of these cmdlets/sections of code (or the entire powershell session) to run/connect to a specific DC server? We have 4 DC servers and it appears that the cmdlets connect to different DCs when the script runs...

    Thursday, January 25, 2018 3:19 PM

Answers

  • Use the full path "ldap://server/cn=$contactName,ou=Contacts,dc=contoso,dc=com"
    • Marked as answer by TLeanna Friday, January 26, 2018 1:58 PM
    Thursday, January 25, 2018 4:40 PM

All replies

    • New-DistributionGroup (use -domaincontroller parameter)
    • Set-DistributionGroup (use -domaincontroller parameter)
    • Set-ADGroup (use -server parameter)
    • New-MailContact (use -domaincontroller parameter)
    • Set-MailContact (use -domaincontroller parameter)
    • Add-DistributionGroupMember (use -domaincontroller parameter)
    • Proposed as answer by jrv Thursday, January 25, 2018 4:19 PM
    Thursday, January 25, 2018 4:17 PM
  • I will try those... 

    Any idea on how I can force the location with these other sections of code:

    $Contact = [ADSI]"LDAP://cn=$contactName,ou=Contacts,dc=contoso,dc=com"
    $Contact.description = "Requested by $owner"
    $Contact.SetInfo()

    I looked for a cmdlet that would allow me to change the Notes & Description for objects, but cannot find one...

    Thursday, January 25, 2018 4:35 PM
  • I will try those... 

    Any idea on how I can force the location with these other sections of code:

    $Contact = [ADSI]"LDAP://cn=$contactName,ou=Contacts,dc=contoso,dc=com"
    $Contact.description = "Requested by $owner"
    $Contact.SetInfo()

    I looked for a cmdlet that would allow me to change the Notes & Description for objects, but cannot find one...

    help Set-AdUser -online

    This allows setting all properties of a contact.  Reading the help is the easiest and fastest way to solve issue but first you need to learn PwoerSHell beyond just copying things you find.


    \_(ツ)_/

    Thursday, January 25, 2018 4:37 PM
  • Use the full path "ldap://server/cn=$contactName,ou=Contacts,dc=contoso,dc=com"
    • Marked as answer by TLeanna Friday, January 26, 2018 1:58 PM
    Thursday, January 25, 2018 4:40 PM
  • I did....

    The Set-MailContact cmdlet does not have any -Description option...

    The Set-DistributionList cmdlet does not have any -Notes option

    And I don't believe from what I researched that a MailContact is not an ADUser which is why that cmdlet would not work....

    Thursday, January 25, 2018 5:19 PM
  • I did....

    The Set-MailContact cmdlet does not have any -Description option...

    The Set-DistributionList cmdlet does not have any -Notes option

    And I don't believe from what I researched that a MailContact is not an ADUser which is why that cmdlet would not work....

    "Notes" and  "Description" are AD attributes.  Use Set-AdUser and Set-AdGroup to set those values.  The ADSI calls are doing just that,

    For Contacts use Set-AdContact.

    You cannot force the ADSI to use a server in the whole session. The CmdLets and ADSI must specify a server on each line.

    First learn PowerShell then learn how to use AD and Exchange and the CmdLets.  We do not fix scripts you have copied from the Internet.  Once you learn the technologies you are asking about you will be better able to ask a question and better equipped to understand the answer.


    \_(ツ)_/

    Thursday, January 25, 2018 5:32 PM
  • I do not see that there is a Set-ADContact cmdlet... 

    Using the Set-ADUser & Set-ADObject cmdlets both return errors that the object does not exist:

    Set-ADUser -Identity MyMailContact  -Replace @{info="Requested by manager"} -Server "thsiserver.contoso.com"
    ** Returns error of Set-ADUser : Cannot find an object with identity: 'MyMailContact' under: 'DC=conotoso,DC=com'

    Set-ADObject -Identity MyMailContact -Replace @{info="Requested by manager"} -DomainController "thisserver.contoso.com"
    ** Returns error of Set-ADObject : A parameter cannot be found that matches parameter name 'DomainController'.

    Both the Set-Contact & Set-MailContact cmdlets do not have a -Notes option in them and the -Replace option does not work either:

    Set-Contact -Identity MyMailContact  -Replace @{info="Requested by manager"} -DomainController "thisserver.contoso.com"
    ** Returns error of Set-Contact : A parameter cannot be found that matches parameter name 'Replace'

    Set-MailContact -Identity MyMailContact -Replace @{info="Requested by manager"} -DomainController "thisserver.conotoso.com"
    ** Returns error of Set-MailContact : A parameter cannot be found that matches parameter name 'Replace'

    Thursday, January 25, 2018 10:10 PM
  • Please carefully read the whole help for these CmdLets.  All of you mistakes are due to failure to read the help.  There is no "DomainController" parameter on any CmdLet anywhere.  You did not get that form the help.  You just made it up.

    "Replace" is available only on AD CmdLets.

    You need to put in some effort to try and understand how each CmdLet works. You cannot guess the answers and then ask for help for things that are obviously documented.

    Please take the time to learn basic PowerShell:  Learn PowerShell  


    \_(ツ)_/

    Thursday, January 25, 2018 10:23 PM
  • I have read every cmdlet that I can think of to try and get this working. Which is the reason I posted the question out here...

    Reading and understanding are two different processes. If you choose not to help me then stop bashing me.

    I will take this to another forum - one that is much more friendly

    Friday, January 26, 2018 1:58 PM
  • The chances are that you either don't have sufficient computer experience or you lack basic PowerShell and AD knowledge.

    Note that technical forums are not intended to be a place for untrained users to get free consulting.

    Be aware that, by default, the help for PowerShell CmdLets is not updated and may show almost no useful information.  Training in PowerShell would have made you aware of this.

    We have given you a  number of solutions to your problem.  We cannot help it is you cannot understand the assistance.

    If this is important then I suggest contacting a consultant to help you sort this out.

    The answers to you issues can also be found by searching online for the CmdLet which should have the latest documentation.  You will still have to learn how to read and understand the help/documentation.  We cannot do that for you.

    Also note that this forum is not for fixing code you have copied from the Internet.  You must be trained in the basics of PowerShell and the technology you are trying to use.  Either you are a technician or not.  Non-technicians should contact a consultant either in or outside of their organization.  These technologies are not trivial and cannot be understood by guessing or asking questions on the Internet.

    Sorry and good luck.


    \_(ツ)_/

    Friday, January 26, 2018 7:14 PM