I am new around here (hope I’m posting this in the right place) and I have a very important question. I am connecting to a remote Exchange server using a remote runspacepool based on this example:
http://msdn.microsoft.com/en-us/library/ee706598%28VS.85%29.aspx
I am able to connect and run commands and it works really well. However, when I try to do more advanced things, like run a scriptblock ( Invoke-Command -scriptblock {} ) I get the exception “ Script block literals are not allowed in restricted language mode or a Data section.”
I am connecting with admin credentials, so that should not be a problem. Browsing msdn, all I have come up with is "PSLanguageMode enum", which might indicate that I must set the PSLanguageMode to PSLanguageMode.FullLanguage, perhaps it is set to PSLanguageMode .RestrictedLanguage
by default? However, this value seems to be set in the initial sessionstate ( runspacePool.InitialSessionState.LanguageMode) but the initial sessionstate is null in my pool (and not assignable)
Any ideas on how to solve this so that I can run scriptblocks on my remote Exchange server?
Thanks a lot in advance, any help is greatly appreciated since I am stuck and must solve this somehow!
Some code (see previous link on msdn):
WSManConnectionInfo connectionInfo = new WSManConnectionInfo (new Uri (connectionUri), schemaName, cred);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism .Kerberos;
connectionInfo.ProxyAuthentication = AuthenticationMechanism .Negotiate;
RunspacePool runspacePool = RunspaceFactory .CreateRunspacePool(1,5,connectionInfo);
Exception:
System.Management.Automation.RemoteException : Script block literals are not allowed in restricted language mode or a Data section.
at System.Management.Automation.PowerShell.EndInvoke(IAsyncResult asyncResult)
--- End of inner exception stack trace ---