powershell - 将 AD 信息移动到 excel 的脚本,有没有办法为描述值编写 if 函数?
问题描述
这里是 PowerShell 的新手,我正在尝试编写一个脚本来通过 powershell 将一些 AD 信息移动到 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.
解决方案
您可以计算-blockdescription
中的值。select
无需在管道中进行。以下是使用计算属性的方法。计算属性是定义为具有名称(“描述”)的哈希表和具有表达式(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
推荐阅读
- typescript - 如何将 json 文件转换为 Deno doc 网站
- regex - Shell - 重构连接数字的字符串正则表达式
- wordpress - 在 wordpress comment_reply_link() 中损坏评论的回复链接
- python - 错误:使用带有通配符的 re.findall 时出现虚假转义(行尾)
- javascript - Ember.js - 运行 ember --version 命令时出错
- python - 是否可以在 tkinter & python 中创建多个表单字段,然后以表格列格式将其提交到输出文本框
- jsp - JSP中注销按钮的会话无效
- javascript - JavaScript - 单击按钮时加载进度条后显示图像
- ios - SwiftUI 中的 animatableData 有什么作用?
- python - 书上是这么说的,但是进口给了追溯?