将AD信息移动到excel的脚本,有没有办法为描述值编写if函数



这里的PowerShell,我正在尝试编写一个脚本来移动一些AD信息以通过Powershell进行Excel。我遇到的问题是,除了所有其他事情之外,我正在尝试让 excel 中的一个字段成为描述字段。从那里我尝试编写一个 if 函数来根据它是否符合描述进行过滤。

get-aduser -Filter * -properties CN,PasswordNeverExpires,LastLogon,description| where {
$_.PasswordNeverExpires -eq "true" } | If ( $_.description -eq "super") {"SU"} Else {"Human"} | Select-Object CN, enabled,samAccountName,LastLogon, description | Export-Csv $path ```
No error message just doesn't display description field in excel.

您可以在 select -block 中计算description的值。无需在管道中进行操作。下面介绍如何使用计算属性执行此操作。计算属性是定义为具有名称("说明"(的哈希表和具有表达式(if/else(的代码块的属性:

get-aduser -Filter * -properties CN,PasswordNeverExpires,LastLogon,description| where {
$_.PasswordNeverExpires -eq "true" } | select CN, enabled,samAccountName,LastLogon,@{Name ="description";Expression={ If ( $_.description -eq "super") {"SU"} Else {"Human"}  }} | Export-Csv $path

最新更新