powershell - 我可以在输出期间使用 Select-Object/Export-CSV 转换对象属性吗?

标签 powershell

我正在使用 Quest AD cmdlet,尤其是 Get-QADUser,从 AD 中提取用户列表并仅返回几个属性。没问题,很简单,但我想在导出到 CSV 之前转换其中一个属性 (parentContainerDN)。

Get-QADUser -name "Froosh" | Select-Object logonName,homeDrive,parentContainerDN | Export-CSV C:\Temp\File.csv

这当然有效,但 parentContainerDN 又长又乱。在将其传递给 Export-CSV 之前,是否有一种简单的方法可以将其替换为 parentContainerDN.Name?

我会对命令行解决方案或脚本片段感到满意。

谢谢!

最佳答案

有一种特殊的语法可以在 select-object 中创建动态属性。试试这个(为了清楚起见添加了包装):

get-qaduser -name "hamilmat" 
    | select-object logonName, homeDrive, 
        @{Name="containerName"; Expression={$_.parentContainerDN.Name}} 
    | export-csv ...

关于powershell - 我可以在输出期间使用 Select-Object/Export-CSV 转换对象属性吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/207166/

相关文章:

powershell - 用嵌套文件夹中的相对符号链接(symbolic link)替换快捷方式

powershell - Azure PowerShell - 提取 Azure SQL 数据库信息

sql - Powershell:使用动态SQL运行存储的proc不起作用

powershell - 将值添加到数组并将其作为 json 有效负载发送 - Powershell Azure

powershell - 用一个 | 替换多个空格(管道)

powershell - 如何解析 Powershell 脚本 block 中的变量

python - 来自 import-csv 的 Powershell ConvertTo-Json 性能不佳

powershell - 使用启动进程在远程 Windows 机器上安装 awscli msi 包

powershell - 为什么总是提示我确认?

powershell - 在powershell中对文本进行数字排序