Get-ADComputer -SearchBase "DC=some,DC=website,DC=net" -Filter * -Properties Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Sort Description | Format-Table Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap | Out-File $env:USERPROFILE\Desktop\AD-Quick-Inventory.txt
上面的代码是我想要的,但是当输出到.txt文件时我只有5列(在描述处停止)。
我如何允许显示所有列。
我尝试了 export-csv,它确实导出了我想要的数据,但它也导出了一堆我没有选择的随机属性。
答案1
某些 cmdLets 只能在管道末端使用(Format-table、Out-File、Export-Csv)。一旦您使用其中任何一个 cmdLets,在其后放置另一个 cmdLets 都会产生垃圾,因为前者已将对象数据转换为非对象数据(如字符串等)。如果您用 替换,format-table
您select-object
将获得一个仅包含您用 选择的属性的 CSV select-object
。
Get-ADComputer -SearchBase "DC=some,DC=website,DC=net" -Filter * `
-Properties Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Select-Object -Property Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Sort Description | `
Export-Csv -Path AD-Quick-Inventory.csv -NoTypeInformation
答案2
如何将 Get-ADComputer 传输到 csv,如下所示:
Get-ADComputer -SearchBase "DC=some,DC=website,DC=net" -Filter * `
-Properties Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Select-Object -Property Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Sort Description | ConvertTo-CSV -NoTypeInformation | Out-File $path