【发布时间】:2020-08-27 14:15:49
【问题描述】:
我需要验证下面的 cmdlet 结果:
Get-AntiPhishPolicy | Select-Object -ExpandProperty targeteduserstoprotect
返回如下:
System Admin; System.Admin@domain.com Display Name;
Display.Name@domain.net
如何与Get-ADUser结合,获取非活跃用户列表?
显示名称
Get-AntiPhishPolicy | Select-Object -ExpandProperty targeteduserstoprotect | Select @{ Name = 'User List'; Expression = { ($_ -split ';')[0] }}
代理地址
Get-AntiPhishPolicy | Select-Object -ExpandProperty targeteduserstoprotect | Select @{ Name = 'User List'; Expression = { ($_ -split ';')[1] }}
Inactive 表示 AD 用户帐户已禁用或找不到匹配的帐户。
Get-AntiPhishPolicy | Select-Object -ExpandProperty targeteduserstoprotect | Where-Object {((Get-ADUser -Filter "PrimarySMTPAddress -neq '$($_.targeteduserstoprotect -split ';' [1] )'" ) -or ("Enabled -eq $True")}
来源:https://docs.microsoft.com/en-us/powershell/module/exchange/get-antiphishpolicy?view=exchange-ps
Because the above is not working for me with the below error:
At line:2 char:178
+ ... ySMTPAddress -neq '$($_.targeteduserstoprotect -split ';' [1] )'" ) - ...
+ ~~~
Unexpected token '[1]' in expression or statement.
At line:2 char:179
+ ... arySMTPAddress -neq '$($_.targeteduserstoprotect -split ';' [1] )'" ) ...
+ ~
Missing type name after '['.
At line:2 char:213
+ ... argeteduserstoprotect -split ';' [1] )'" ) -or ("Enabled -eq $True")}
+ ~
Missing closing ')' in expression.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
【问题讨论】:
-
乍一看,我会说一个好的代码编辑器,比如Visual Studio Code,会在这里帮助你很多。在你运行任何东西之前就存在语法错误。在你的
Where-Object中,$_.targeteduserstoprotect已经不存在了,应该把Select-Object -ExpandProperty后面的$_替换成$_。拆分部分应该更像这样($_ -split ';')[1]。我不知道-or ("Enabled -eq $True")的目的是什么。 -
好的,它正在部分工作。如何根据电子邮件地址 ($_.ProxyAddresses) 将管道结果匹配到 Get-ADUser?我需要得到那些失败的。
标签: powershell