将数据转换为CSV时,Powershell是否支持使用自定义 header 名称?我正在从Active Directory转换用户数据,并希望在标题中使用属性名称以外的其他名称。
我的代码:
$adusers | select givenName,sn,telephoneNumber,SamAccountName,physicalDeliveryOfficeName,Title,mobile | ConvertTo-Csv -Delimiter ';' | Out-File -FilePath $thefilepath
最佳答案
有很多方法可以给这只猫蒙皮。
您可以从输出中创建新的自定义对象,并根据需要命名属性:
$adOutput | Foreach-Object{
New-Object PSObject -Property @{
UserName = $_.SamAccountName
...
}
} | Export-Csv ...
您也可以使用计算出的属性来做到这一点:
$adOutput | Select Name,@{Name='UserName';Expression={$_.SamAccountName}} | Export-Csv ...
关于powershell - Powershell ConvertTo-CSV自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16690857/