Hi, I’m trying to Identify the DC in use by get-ADUser without hard-coding the DC name in the -server param for redundancy reasons. (I know i can specify the DC - just trying not to).
$FQDN = domain.forest.corp
#Will:
get-addomaincontroller -Server $FQDN
#use the same DC as
get-ADUser -server $FQDN
#If i run them one after another in this order?
BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Thanks for the answer. I guess that’s what i figured. I guess i am asking if the -server switch will work in the same way and provide the same result (if the server is up), on both commands.
As for why - I would like it to work if a DC is down for patching or whatever reason.
But you don’t need to provide a server at all. PowerShell (or actually the underlying dotNet) will choose the nearest available server. Actually providing a particular server makes your code less robust.
Ah yes, but the script runs on multiple domains from a server not in that domain, and so the $FQDN is provided via function prams and will be different on each run. So it needs to be present.
If you are creating then updating objects, you’ll want to ensure that you use the same DC. For each iteration, detect the DC then use that for all actions for that one object. Perhaps on subsequent iterations, just verify if the DC is available. Don’t hard code a specific value and don’t use the DNS domain name.
Actually not. If you’re just querying an AD it doesn’t matter if you use the same DC or not. Then it will be enough to specify the domain like you showed in your initial question.