简体   繁体   中英

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. As I was doing it I realized that I could of just wrote a batch file or Powershell Script to do this for me. I typed in the command "wmic bios get serialnumber" and it gave me the serial number for my machine. 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 ? 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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