【发布时间】:2021-08-16 07:18:01
【问题描述】:
我有以下 powershell 脚本
$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>
但我收到以下错误
+ 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.
我在get-mailbox 上测试了几种语法组合,其中包括:
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>
但我不能这样做,因为交换服务器中没有一个邮箱,所以我必须使其更灵活
【问题讨论】:
标签: powershell exchange-server powershell-2.0 powershell-4.0 exchange-server-2010