How many developers have encountered the following errors when attempting to write remote PowerShell commands against Exchange?
Function declarations are not allowed in restricted language mode or a Data section. Property references are not allowed in restricted language mode or a Data section. Assignment statements are not allowed in restricted language mode or a Data section.
The easiest solution I've found to this problem is to go into the Exchange Webmail IIS Manager, find the PowerShell application, and change the PSLanguageMode option to FullLanguage in the Application Settings.
By default, this value is typically set to RestrictedLanguage, which results in the errors.
After making these changes, you should be able to code against Exchange using .NET Remote PowerShell commands with ease.
Please remember to secure access to the exchange server's PowerShell application! Restrict by IP addresses and enable other security measures as required.