I'm trying to run the test-mailflow cmdlet, within the invoke-command cmdlet. I'm on a Client Access Server and I can issue the test-mapiconnectivity cmdlet against a user. However in order to run the test-mailflow cmdlet, I need to be on the mailbox server that the user is on.
I'm referencing this article: http://technet.microsoft.com/en-us/library/hh849719.aspx
The problem is I keep getting the error:
A variable that cannot be referenced in restricted language mode or a Data section is being referenced. Variables thatcan be referenced include the following: $PSCulture, $PSUICulture, $true, $false, and $null. + CategoryInfo : ParserError: (data:Token) , ParseException + FullyQualifiedErrorId : VariableReferenceNotSupportedInDataSection
Anyone know what I'm missing or how I can get the invoke-command to run the mailflow test remotely?
Welcome to tricky.
So, Remoting - which is what Invoke-Command uses - can connect to one of many different endpoints ("session configurations") on a remote server. The one you're connecting to is configured with restrictions, including - based on the error message - turning off the PowerShell scripting language. So whatever you've remoted into doesn't support variables.
You've got some choices.
First, connect to a different endpoint. Run Get-PSSessionConfiguration on the server to see what it's got. If it has a default "Microsoft.PowerShell" endpoint, connect to that - use the -ConfigurationName parameter of Invoke-Command.
Second, don't use a variable. Try using (nested) commands in parentheses instead, if you can construct your command that way. Happy to help if you want to show me what you're up to.