I have the following powershell script
$mailbox = "testmail"
$i=invoke-command -Session $session -ScriptBlock { get-mailbox -identity $mailbox | get-mailboxpermission | Select-Object Identity,User,AccessRights,ExtendedRights } -HideComputerName | Where-Object {($_.User -like '*1023') -and ($_.AccessRights -like 'FullAccess*')}
write-host "The I values :"$i <br>
But I am getting the following error
+ get-mailbox -identity $mailbox | get-mailboxpermission | Select-Obje ...
+ ~~~~~~~~
A variable that cannot be referenced in restricted language mode or a Data section is being referenced. Variables that can be referenced include the following: $PSCulture,
$PSUICulture, $true, $false, $null.
I tested several combination on the syntax on the get-mailbox
which included the following :
get-mailbox -identity '$mailbox'
get-mailbox -identity "'$mailbox'"
$i=invoke-command -Session $session -ScriptBlock { get-mailbox -identity testmail | get-mailboxpermission | Select-Object Identity,User,AccessRights,ExtendedRights } -HideComputerName | Where-Object {($_.User -like '*1023') -and ($_.AccessRights -like 'FullAccess*')} <br>
But I cant do it this way because there are not one mail box in the exchange server, so I must make it more flexible
Thy the $using scope by changing $mailbox to $using:mailbox within the ScriptBlock.