导出AD用户msExchExtensionCustomAttribute2至CSV异常,请求协助
解决AD用户属性导出CSV/TXT的问题
问题原因
你使用-ExpandProperty后,输出的是msExchExtensionCustomAttribute2的原始值(比如字符串),而Export-Csv是针对对象导出的工具,它会提取该值的内置属性(比如字符串的Length)作为CSV列,导致输出并非你需要的属性内容。
解决方案
方案1:导出带属性名的CSV
保留对象结构,明确指定要导出的属性列:
Get-ADUser -Identity test -Properties msExchExtensionCustomAttribute2 | Select-Object @{Name='msExchExtensionCustomAttribute2'; Expression={$_.msExchExtensionCustomAttribute2}} | Export-Csv -Path C:\temp\test.csv -NoTypeInformation
方案2:导出纯文本到TXT
如果只需要属性的纯文本值,直接用Out-File更简单直接:
Get-ADUser -Identity test -Properties msExchExtensionCustomAttribute2 | Select-Object -ExpandProperty msExchExtensionCustomAttribute2 | Out-File -Path C:\temp\test.txt -Encoding UTF8
内容的提问来源于stack exchange,提问作者Dhiman Sau
相关产品推荐
相关产品推荐

