Function Get-GmailAlias ($ID) {
$a = (Get-RemoteMailbox $ID |
Select-Object DisplayName,PrimarySmtpAddress, @{ Name="EmailAddresses"; Expression={$_.EmailAddresses | Where-Object { $_.PrefixString -ceq "smtp" } | ForEach-Object { $_.SmtpAddress }}}).EmailAddresses |
Where-Object { $_ -like '*gmail*' }
$b=@()
foreach ($mem in $a) {
$b += "'$mem'"
}
$c= $b -join ', '
return $c
}
当您使用 UPN 调用该函数时,结果将如下所示:
'kiran.kumar@gmail.com', 'kiran_kumar@gmail.com'
我正在尝试在下面的 cmdlet 中调用该函数。
Set-RemoteMailbox kpv@gmail.com -EmailAddresses @{Remove=Get-GmailAlias('kpv@gmail.com')}
我得到以下输出:
WARNING: The command completed successfully but no settings of 'XXX/XXX/XXX/XXX/XXX/XXX/Kiran Kumar' have been modified.
我尝试了以下方法:
>@{Remove=$(Get-GmailAlias('kpv@gmail.com'))} # Alternative-1
>$c = Get-GmailAlias('kpv@gmail.com')
@{Remove="$c"} # Alternative-2
>$c = "@{Remove = $(Get-GmailAlias('kpv@gmail.com'))}"
Set-RemoteMailbox kpv@gmail.com -EmailAddresses $c # Alternative-3
以上都没有奏效,alternative-3 也给了我以下错误:
Cannot process argument transformation on parameter 'EmailAddresses'. Cannot convert value "@{Remove = 'kiran.kumar@gmail.com', 'kiran_kumar@gmail.com'}" to type "Microsoft.Exchange.Data.ProxyAddressCollection".
请帮助我找出为什么我无法在 -EmailAddresses 中执行变量/函数。