如何将 Get-ADComputer 结果设置为对象 [英] How to set Get-ADComputer result as object
本文介绍了如何将 Get-ADComputer 结果设置为对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个 Powershell 命令:
I have this Powershell command:
Get-ADComputer -filter { Name -like 'srv*' } | Select -Expand dnshostname | Export-CSV -path ad_export.csv
在 CSV 中,它只写入字符串的长度.我读到我必须通过管道将对象导出到 Export-CSV,以便它写入服务器名称,而不仅仅是长度.我该怎么做?
In the CSV it only writes the length of the Strings. I read that I have to pipe an object to Export-CSV so it writes the Servernames and not only the length. How do I do that?
推荐答案
根据需求,您可以使用:
Based on the requirement , you can use :
Get-ADComputer -Filter 'ObjectClass -eq "Computer"' | Select -Expand DNSHostName | Export-CSV -path ad_export.csv
# Getting just the hostname
Get-ADComputer -Filter * | Select -Expand Name | Export-CSV -path ad_export.csv
# Getting a specific computer
Get-ADComputer -Filter { Name -eq 'server2012' } -Propert LastLogonTimestamp | Select DistinguishedName, LastLogonTimestamp | Format-Table -AutoSize | Export-CSV -path ad_export.csv
注意:如果需要,您也可以使用where"子句.希望这足以满足您的需求
Note: You can use the "where" clause also if required. Hope This suffice your need
这篇关于如何将 Get-ADComputer 结果设置为对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文