简体   繁体   English

如何在Excel电子表格中导出批处理文件/ Powershell脚本的输出

[英]How to export output of batch file/Powershell Script in a Excel Spreadsheet

I have been asked to go around the entire building and document the serial numbers, and system information on all of the PC's in the network. 我被要求遍历整个建筑物,并在网络中所有PC上记录序列号和系统信息。 As I was doing it I realized that I could of just wrote a batch file or Powershell Script to do this for me. 当我这样做的时候,我意识到我可以编写一个批处理文件或Powershell脚本来为我做这件事。 I typed in the command "wmic bios get serialnumber" and it gave me the serial number for my machine. 我输入命令“ wmic bios get serialnumber”,它给了我机器的序列号。 Is there a way to Get all of the information such as the processor, memory, ip address, and serial number and output it in a excel spreadsheet ? 有没有一种方法可以获取所有信息,例如处理器,内存,IP地址和序列号,并将其输出到excel电子表格中? If it can only be exported in a text file that is fine. 如果只能将其导出到可以的文本文件中。 I would like to save it on my server. 我想将其保存在我的服务器上。 I don't know how I can save it all to one text file. 我不知道如何将它们全部保存到一个文本文件中。 I realize that I could have the batch file make a text file of its own with the >> %COMPUTERNAME%.txt command. 我意识到我可以使用>>%COMPUTERNAME%.txt命令使批处理文件创建自己的文本文件。

Any help or suggestions would be great! 任何帮助或建议将是巨大的! Thanks! 谢谢!

Get-WmiObject win32_processor | Findstr ('Name') | Format-List
$env:COMPUTERNAME | Format-List
wmic bios get serialnumber /Format
Get-WmiObject -Class Win32_ComputerSystem | Findstr ('Model') | Format-List
Get-WmiObject -Class Win32_ComputerSystem | Findstr ('Manufacturer') | Format-List
Get-WmiObject -Class Win32_ComputerSystem | Findstr ('Name') | Format-List
(systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim() | Format-List
Export-CSV -Path C:\Users\ars001\%COMPUTERNAME%.csv | Format-List

Ok, you evidently put in some effort to get the commands to at least gather the info and what classes you'd need for what details, so I'll give you this much... 好的,您显然已经付出了一些努力来获取命令,以至少收集信息以及所需的类以了解详细信息,因此,我将为您提供很多帮助...

$Computers = Get-Content C:\Path\To\ComputerList.txt
[array]$Results = $Record = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $PC | select Model,Manufacturer,Name,TotalPhysicalMemory
$Results[0] | Add-Member 'Processor' $(Get-WmiObject win32_processor -ComputerName $PC | % Name)
$Results[0] | Add-Member 'SerialNumber' $(Get-WmiObject bios -ComputerName $PC |% serialnumber)
ForEach($PC in $Computers){
    If(!(Test-Connection $PC -Quiet) -or $PC -eq $env:COMPUTERNAME){Continue}
    $Record = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $PC | select Model,Manufacturer,Name,TotalPhysicalMemory
    $Record | Add-Member 'Processor' $(Get-WmiObject win32_processor -ComputerName $PC | % Name)
    $Results += $Record | Add-Member 'SerialNumber' $(Get-WmiObject bios -ComputerName $PC |% serialnumber) -PassThru
}
$Results | Export-Csv c:\Path\To\Output.csv -NoTypeInformation

Then you just need to edit the paths, and have a list of computers saved as a text file. 然后,您只需要编辑路径,并将计算机列表保存为文本文件即可。 If you have the AD module installed you can query AD for that info instead. 如果安装了AD模块,则可以向AD查询该信息。

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

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