unable to run remote PowerShell set-xx scripts.

Hello peeps,

Having a problem running remote PowerShell commands, hoping someone can shed a little light into what I'm doing wrong?

$cred = Get-Credential
$sessionoption = New-PSSessionOption -SkipCNCheck
$exchangesession = New-PSSession -Credential $cred -ConnectionUri https://example.com/PowerShell -ConfigurationName Microsoft.Exchange -AllowRedirection -SessionOption $sessionoption
enter-PSSession $exchangesession
Get-Mailbox user1 | select exchangeVersion
Get-Mailbox user2 | select prohibitsendquota
New-Mailbox -Name "User3" -userprincipalname user3@example.com
Set-MailboxautoReplyConfiguration user1 -starttime 05/05/2015 -Endtime 06/05/2015 -AutoReplyState Scheduled -InternalMessage ="test" -ExternalMessage "test"
get-exchangeserver


If I manually input this from any PowerShell window it works fine. Running it from ISE as the basis of a much larger script it fails on the set-mailboxautoreplyconfiguration with the below but then runs the last get-exchangeserver command.

Set-MailboxautoReplyConfiguration : Cannot find information about the local server localcomputer.example.com in Active Directory. 
This may be related to a change in the server name.
At line:8 char:1
+ Set-MailboxautoReplyConfiguration user1 -starttime 05/05/2015 -Endtime 06/05/ ...

Any ideas? It's probably something really obvious but dammed if I know.

Thanks

May 1st, 2015 5:35am

Hi Graham,

The secret to using Windows PowerShell remoting to remotely manage a server running Exchange Server  is to use implicit remoting instead of explicitly connecting to a remote Windows PowerShell session. Here are the steps required to create an implicit remote Windows PowerShell session.

  1. Use the Get-Credential cmdlet to obtain credentials for the server running Exchange Server 2010. Store the returned credential object in a variable.
  2. Use the New-PSSession cmdlet to create a new session on the server. Specify the ConnectionUri in the form of http://servername/powershell and supply the credential object from step 1 to the Credential parameter. Store the returned session object in a variable.
  3. Use the Import-PSSession cmdlet to connect to the session created in step 2.

Try using the below:

$cred = Get-Credential

$sessionoption = New-PSSessionOption -SkipCNCheck

$exchangesession = New-PSSession -Credential $cred -ConnectionUri https://example.com/PowerShell -ConfigurationName Microsoft.Exchange -AllowRedirection -SessionOption $sessionoption

Import-PSSession $exchangesession
Get-Mailbox user1 | select exchangeVersion
Get-Mailbox user2 | select prohibitsendquota
Set-MailboxautoReplyConfiguration user1 -starttime 05/05/2015 -Endtime 06/05/2015 -AutoReplyState Scheduled -InternalMessage ="test" -ExternalMessage "test"
get-exchangeserver

References:

Learn How to Use PowerShell to Run Exchange Commands Remotely


Free Windows Admin Tool Kit Click here and download it now
May 8th, 2015 2:23pm

Hi Graham,

The secret to using Windows PowerShell remoting to remotely manage a server running Exchange Server  is to use implicit remoting instead of explicitly connecting to a remote Windows PowerShell session. Here are the steps required to create an implicit remote Windows PowerShell session.

  1. Use the Get-Credential cmdlet to obtain credentials for the server running Exchange Server 2010. Store the returned credential object in a variable.
  2. Use the New-PSSession cmdlet to create a new session on the server. Specify the ConnectionUri in the form of http://servername/powershell and supply the credential object from step 1 to the Credential parameter. Store the returned session object in a variable.
  3. Use the Import-PSSession cmdlet to connect to the session created in step 2.

Try using the below:

$cred = Get-Credential

$sessionoption = New-PSSessionOption -SkipCNCheck

$exchangesession = New-PSSession -Credential $cred -ConnectionUri https://example.com/PowerShell -ConfigurationName Microsoft.Exchange -AllowRedirection -SessionOption $sessionoption

Import-PSSession $exchangesession
Get-Mailbox user1 | select exchangeVersion
Get-Mailbox user2 | select prohibitsendquota
Set-MailboxautoReplyConfiguration user1 -starttime 05/05/2015 -Endtime 06/05/2015 -AutoReplyState Scheduled -InternalMessage ="test" -ExternalMessage "test"
get-exchangeserver

References:

Learn How to Use PowerShell to Run Exchange Commands Remotely

May 11th, 2015 4:15am

Hi Graham,

My pleasure. :)

Free Windows Admin Tool Kit Click here and download it now
May 11th, 2015 4:26am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics