简体   繁体   English

在powershell中使用Export-Csv时,如何从输出中排除#TYPE Selected.System.Management.ManagementObject

[英]While using Export-Csv in powershell, how to exclude #TYPE Selected.System.Management.ManagementObject from the output

I am using the following PowerShell script to obtain Name, DisplayName, State, StartMode and PathName of all windows services of a local machine and then export the output to a csv file using the Export-csv cmdlet, 我使用以下PowerShell脚本获取本地计算机的所有Windows服务的Name,DisplayName,State,StartMode和PathName,然后使用Export-csv cmdlet将输出导出到csv文件,

Get-WmiObject win32_service | Select Name, DisplayName, State, StartMode, PathName | Export-Csv C:/ListOfServices.csv

the script works fine but the problem is, the first row of the output csv file contains 该脚本工作正常,但问题是,输出csv文件的第一行包含

#TYPE Selected.System.Management.ManagementObject

Is there any way to exclude this line from the output? 有没有办法从输出中排除这一行? I am preparing a script to get all these details from all server machines in the network, so excluding this line becomes important. 我正在准备一个脚本来从网络中的所有服务器机器获取所有这些细节,因此排除此行变得很重要。

Add the -NoTypeInformation switch in your Export-CSV command, like this: Export-CSV命令中添加-NoTypeInformation开关,如下所示:

Get-WmiObject -Class win32_service |
Select Name, DisplayName, State, StartMode, PathName |
Export-Csv -NoTypeInformation -Path C:/ListOfServices.csv

you need to include -NoTypeInformation in export-csv command to avoid 你需要在export-csv命令中包含-NoTypeInformation以避免

TYPE Selected.System.Management.ManagementObject TYPE Selected.System.Management.ManagementObject

ex: Export-Csv -Path "your path for the export file" -NoTypeInformation 例如: Export-Csv -Path "your path for the export file" -NoTypeInformation

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

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