I'm trying to set the -server flag globally for a whole script using the Active Directory cmdlets.
My issue is that I am running a script from a different domain, and have a few domains I need to execute these commands on, from a single management domain.
Example:
Get-ADUser 'john' -server domain1.acme.com
However I'd like to just run:
Get-ADUser 'john'
from domain2, without having to specify a -server flag every time I use an AD cmdlet.
Currently, I am simply declaring a $server variable and inserting it into every command, e.g. Get-ADUser 'john' -server $server
But this is rather messy and I feel like there must be a better way. My research has yielded nothing.