Hi All
Hope someone can give me some advice. I have a shared domain called DOM1 this domain is a single domain inside its own forest. It is used to run management servers that manages multiple customers' domains. Each customer has their own separate forest &
domain. They are all connected to DOM1 via WAN links with firewalls inbetween. All relevant firewall ports for Powershell are allowed. Connectivity is not a problem - I can issue powershell commands to a particular domain on demand without any issue.
My problem is this :
I have a single server ( DC ) in DOM1 where I run all my scripts from. Can someone please tell me what the best way would be to connect to these multiple domains if I need to run a single script against all of them - find all Exchange 2010 servers for instance.
So far I have done the following, but it seems a bit clunky to me.
I'd like to enter and exit PSSessions on demand depending on which domain the query runs on, but still have the session open so I can run other commands without having to destroy a particular session each time I want to switch domains.
Hope you understand what I mean:
Here I connect to each customer's exchange 2010 server to import the exchange 2010 cmd-lets to my console, I then save the session in a variable so I can import it on demand whenever I need it :
$PSSessionOptions = New-PSSessionOption -SkipCACheck -SkipRevocationCheck -SkipCNCheck
$global:cust1 = New-PSSession -Name CUST1 -ConfigurationName Microsoft.Exchange -ConnectionUri https://exchangesrv.customer1.local/PowerShell -SessionOption $PSSessionOptions -credential (get-credential "customer1\")
$global:cust2 = New-PSSession -Name CUST2 -ConfigurationName Microsoft.Exchange -ConnectionUri https://exchangesrv.customer2.local/PowerShell -SessionOption $PSSessionOptions -credential (get-credential "customer2\")
Here I am doing a basic exchange query against the two separate customers. I firstly import the session var, then run my command against that customer's environment and then remove the PSSession so that I can connect to the next customer.
Import-PSSession $cust1
Get-ExchangeServer | ?{$_.AdmindisplayVersion -like "*14*"} | Select Name, AdminDisplayVersion
Remove-PSSession -Name CUST1
Import-Pssession $cust2
Get-ExchangeServer | ?{$_.AdmindisplayVersion -like "*14*"} | Select Name, AdminDisplayVersion
Remove-PSSession -Name CUST2
This is where I need help, I feel that I'm not doing it properly, and that there is another way - although at this stage, I cannot see any other way to do this. The problem is that the session gets removed ( otherwise I cannot connect to the next customer
), so next time I want to run another command on the first customer, I have to first establish a new session. Is there no way to switch between sessions without destroying the other first ?
Thanks for your help !
Regards