[英]Export Multi column Excel spreadsheet from Powershell script
I have been working at this for what seems like way too long now.我一直在做这件事似乎太久了。 I am pulling all of the ADgroups names and descriptions in my domain.我正在提取我域中的所有 ADgroups 名称和描述。 At this point it doesn't necessarily matter but its eating at me.在这一点上,它并不一定重要,但它在吃我。
$exportList = @()
$ADgroups = Get-ADGroup -Filter * -Properties Description
Foreach ($group in $adgroups){
$GroupObj = New-Object System.Object
$GroupObj | Add-Member -Type NoteProperty -Name Name -Value $group.Name
$GroupObj | Add-Member -Type NoteProperty -Name Description -Value $group.Description
$exportList += $GroupObj
}
$exportList | Out-File C:\test\ADGroups.csv
And the file comes out like this where all of the data is within column A文件像这样出现,其中所有数据都在 A 列中
but I would like for the name to show in column A and the Description to show in column BI have tried making different Arrays and tried calling the properties in different ways but nothing I have tried yet has worked and I am sure that I am missing something very simple.但我希望名称显示在 A 列中,描述显示在 BI 列中尝试制作不同的 Arrays 并尝试以不同的方式调用属性,但我尝试过的任何方法都没有奏效,我确信我错过了一些东西很简单。
You're using Out-File
Instead of Export-CSV
which export a text file instead of a comma separated file您正在使用Out-File
而不是Export-CSV
导出文本文件而不是逗号分隔文件
Replace the:更换:
$exportList | Out-File C:\test\ADGroups.csv
To:至:
$exportList | Export-CSV C:\test\ADGroups.csv
Also, You can cut some lines and simply do:此外,您可以剪切一些行并简单地执行以下操作:
Get-ADGroup -Filter * -Properties Description |
Select Name,Description | Export-CSV C:\test\ADGroups.csv
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.