Remote executing Exchange changes
-
Wednesday, December 12, 2012 3:38 PM
I am trying to run a script that changes the permissions on user calendars after having created a user. The script works as intended if I run it on the local Exchange server, but ... if I use invoke-command to run it from the creating AD-server
PS C:\Users\Administrator.FSYD> invoke-command -Filepath C:\install\SetCalendarPermissions.ps1 -computername fsyd-cas01
then I get
Value cannot be null.
Parameter name: serverSettings
+ CategoryInfo : NotSpecified: (:) [Get-Mailbox], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.Exchange.Management.RecipientTasks.GetMailbox
Cannot bind argument to parameter 'Identity' because it is null.
+ CategoryInfo : InvalidData: (:) [Get-MailboxFolderStatistics], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Exchange.Management.Tasks.GetMa
ilboxFolderStatistics
Updating calendar permission for ...
Cannot bind argument to parameter 'Identity' because it is null.
+ CategoryInfo : InvalidData: (:) [Set-MailboxFolderPermission], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Exchange.Management.StoreTasks.
SetMailboxFolderPermissionTo a beginner it looks like it can't get the Exchange specific data from the server because it's not run parsed on the Exchange server?
Is there some general observation on script syntax that needs amended so it runs from a remote server (i.e. should I add the exchange server name to commands somewhere or whatever?)
All Replies
-
Wednesday, December 12, 2012 3:59 PMModerator
Add this to the top of your script:
$ex = new-pssession -configurationname Microsoft.Exchange -ConnectionURI http://fsyd-cas01/powershell/ -authentication kerberos Import-PSSession $ex
and then run it locally on the creating AD server.[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
- Proposed As Answer by Daniel.Sommer Thursday, December 13, 2012 7:33 AM
- Marked As Answer by Shieldfire Friday, December 14, 2012 9:45 AM
-
Wednesday, December 12, 2012 4:01 PM
Hi
I solved the Probelm by installing the Exchange management tools on my client.
Then just import the Exchange modules in PS.
For Exchange 2010 you need to use a connect String for the PSSession
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://[CAS-Server]/PowerShell/ -Authentication Kerberos Import-PSSession $Session -AllowClobber
then you can run your script locally and it is executed on the Exchange.
Regards
Dan- Proposed As Answer by Daniel.Sommer Thursday, December 13, 2012 7:32 AM
-
Thursday, December 13, 2012 5:19 AMThanks to both, I'll give this a look
-
Thursday, December 13, 2012 8:45 AM
Hmm I now got
PS C:\Users\Administrator.FSYD> invoke-command -Filepath C:\install\SetCalendarPermissions.ps1 -computername fsyd-cas01
[fsyd-cas01] Connecting to remote server failed with the following error message : A specified logon session does not e
xist. It may already have been terminated. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportExc
eption
+ FullyQualifiedErrorId : PSSessionOpenFailed
Cannot validate argument on parameter 'Session'. The argument is null. Supply a non-null argument and try the command a
gain.
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand
Value cannot be null.I obviously need to check the about_Remote_Troubleshooting text =(
-
Thursday, December 13, 2012 9:43 AMRemoting is not set up on remote system
¯\_(ツ)_/¯
-
Thursday, December 13, 2012 9:50 AM
I've spent a bit of time and found lots of references although it seems nothing exactly matches this scenario. Any ideas anyone?
-
Thursday, December 13, 2012 10:53 AM
Can you remote into the Exchange server?
¯\_(ツ)_/¯
-
Thursday, December 13, 2012 11:15 AMModerator
What version of Exchange are you running?
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
-
Thursday, December 13, 2012 1:17 PMYes I can remote into Exchange and I'm using Exchange 2010.
-
Thursday, December 13, 2012 1:25 PMModeratorRe-read the solution I posted. Add the cmdlets to set up and import the session to your script, and then run that script on the LOCAL machine, NOT in a remote session on the Exchange server.
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
-
Thursday, December 13, 2012 1:29 PM
Ah, sorry ...
I need to run from a remote server though. I can run it on the local server already, unchanged. Maybe it is not possible to run it remotely then? Or maybe I'm just confuddled.
- What I am doing is adding your solution to the script on a remote server
- Remoting to the Exchange server running the script from the non-Exchange server.
Maybe it's wrong =(
- Edited by Shieldfire Thursday, December 13, 2012 1:32 PM
-
Thursday, December 13, 2012 1:35 PMModerator
We don't seem to be communicating. By "local sever" I don't mean the Exchange server. I mean the server that's actually running the script (what you describe as "the creating AD server").
Replace the invoke-command with just
./C:\install\SetCalendarPermissions.ps1
[string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
-
Friday, December 14, 2012 9:44 AMAh, now I'm with you - and now it actually works. Thanks.

