简体   繁体   English

将 powershell 导出到 CSV 的问题

[英]Issues exporting powershell to CSV

It has been many moons since I have last done this and I am having problems exporting some commands to CSV. The biggest one that is getting me right now is自从我上次这样做以来已经过去了很多个月,我在将一些命令导出到 CSV 时遇到了问题。现在最让我烦恼的是

$ADGroupList = Get-ADGroup -Filter * -property * | Select Name -ExpandProperty Name | Sort
ForEach($Group in $ADGroupList) 
{
Write-Host "Group: "$Group.Name
Get-ADGroupMember -Identity $Group | Select Name -ExpandProperty Name | Sort
Write-Host ""
}
Export-Csv -path "c:\Temp\test675.csv"

Works fine with out trying to export but the second I try to export the command will run and either generate a blank file or no file at all.尝试导出时工作正常,但第二次我尝试导出命令将运行并生成空白文件或根本不生成文件。

I am able to run other commands with out a issue exporting them to csv. Thanks for any help in advance.我能够运行其他命令而不会出现问题,将它们导出到 csv。提前感谢您的帮助。

Tim,蒂姆,

From what I can see you're not giving Export-Csv anything to write.据我所见,您没有给 Export-Csv 任何可写的内容。 Try this:试试这个:

$ADGroupList = Get-ADGroup -Filter * -property * | Select Name -ExpandProperty Name | Sort
ForEach($Group in $ADGroupList) 
{
Write-Host "Group: "$Group.Name
Get-ADGroupMember -Identity $Group | 
  Select Name -ExpandProperty Name | 
  Sort                             |
  Export-Csv -path "c:\Temp\test675.csv"
Write-Host ""
}

I'd test this but I don't have access to ActiveDirectory.我会对此进行测试,但我无权访问 ActiveDirectory。 Also the Write-Hosts you probably don't want in the.csv file as they won't play well with the format, headers & columns.此外,您可能不希望在 .csv 文件中使用 Write-Hosts,因为它们不能很好地与格式、标题和列一起使用。

HTH HTH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM