Welcome › Forums › General PowerShell Q&A › How to create multiple PSSession to exchange management shell
- This topic has 6 replies, 4 voices, and was last updated 4 weeks ago by
Participant.
-
AuthorPosts
-
-
December 22, 2020 at 5:01 am #281785
Hi
I am trying to create multiple PSSession to exchange management shell. I can’t figure out how to get this done. The code below isPowerShell1234567foreach ($Server in $Serverlist) {$UserCredential = Get-Credential$MySession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$Server.globalnet.lcl/PowerShell/ -Authentication Kerberos -Credential $UserCredentialImport-PSSession $MySessionGet-MailboxDatabaseCopyStatus | Select-Object Name, Status, activationpreference | Format-Table -AutoSize}Get-PSSession | Remove-PSSession -
December 22, 2020 at 9:30 am #281825
Hello,
Can you please elaborate? What the goal?
Are you connecting to all servers using same credentials?
Thank you.
-
December 22, 2020 at 9:45 am #281828PowerShell12345678foreach ($Server in $Serverlist) {$uri = "http://$Server.globalnet.lcl/PowerShell/"$UserCredential = Get-Credential$MySession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $uri -Authentication Kerberos -Credential $UserCredentialInvoke-Command -Session $MySession -ScriptBlock {Get-MailboxDatabaseCopyStatus | Select-Object Name, Status, activationpreference}}Get-PSSession | Remove-PSSession
-
December 22, 2020 at 9:50 am #281834
Try to use Invoke-Command with Session parameter.
You can try something similar to this:
PowerShell12$s = New-PSSession -ComputerName Server02 -Credential Domain01\User01Invoke-Command -Session $s -ScriptBlock {Get-MaboxDatabaseSatus}Or this:
PowerShell123456$parameters = @{ComputerName = "Server01", "Server02", "TST-0143", "localhost"ConfigurationName = 'MySession.PowerShell'ScriptBlock = { Get-MaboxDatabaseSatus }}Invoke-Command @parametersHope that helps.
-
December 22, 2020 at 10:19 am #281849
Oh, thanks. It’s functioning.
I tried to add the line below and received error.Error: the term format table is not recognized as the name of a cmdlet
PowerShell123Invoke-Command -Session $MySession -ScriptBlock {Get-MailboxDatabaseCopyStatus | Select-Object Name, Status, activationpreference | Format-Table -Autosize}} -
December 22, 2020 at 4:56 pm #281957
You should Format-Table outside of the Invoke-Command as it’s a formatting command. The data needs to be serialized and sent over and I’m fairly certain that breaks with the Format-* commands.
PowerShell123Invoke-Command -Session $MySession -ScriptBlock {Get-MailboxDatabaseCopyStatus | Select-Object Name, Status, activationpreference}} | Format-Table -Autosize-
December 22, 2020 at 7:13 pm #281969
Thanks. It is working now. 🙂
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.