Hi All, I am trying to run cmdlets from VB.NET. I managed to create a session to a remote session and to run either basic powershell commands or Exchange 2010 cmdlets. However I have a problem when trying to run more complex scripts, like
"Get-Mailbox | Where-Object {$_.database -match "database"}"
because I get the error
" Script block literals are not allowed in restricted language mode or a Data section".
This problem only happens with Exchange cmdlets, while using the "http://schemas.microsoft.com/powershell/Microsoft.Exchange" URI.
I hope my question is clear, let me know if you need more details. Thank you a lot for your help because I have been struggling for few days with that now.
I believe there migtht be a way to create a new PSSession and then import the exchange cmdlets locally but I would prefer avoiding that as it takes a long time to import the cmdlets.
Olivier.
Why don't you import only the Exchange cmdlets that you really need? You don't have to import them all.
That's an excellent suggestion, that I will surely use often. I did not know that was possible. I'll try that today.
However I have tested in the remote shell (not in .NET yet) to import the command while creating a new PS-SESSION but it still says that the "restricted language mode" prevent from runnign script blocks, or references to variables such as $_ .
How can we get rid of this restriction ?
Thank you.
Well, in order to remove the restriction I believe that one must create its own "PSSessionConfiguration" on the actual server using "register-PSSessionConfiguration" and then a startupscript and other options can be set.
However I could not manager to load the Exchange cmdlets in this way...
Can you share the full New-PSSession command you're executing to connect to Exchange?