Powershell Output formatting


hello,

       i'm trying make power shell script gather many different computer names , put computer names, model of computer, , serial number text file can opened in excel. when opened in excel want data in different columns. command format use this. here have .

## set variable computers

$comp = get-content -path "f:\scripts\comps.txt"



foreach ($cname in $comp) {
    $out = get-wmiobject -class win32_computersystem -computername $cname | foreach-object {$_.model}
    $serial = get-wmiobject win32_bios | foreach-object {$_.serialnumber}
add-content -path f:\scripts\output\results.txt -value ($cname,$out,$serial) } 

hi,

create custom object data you're looking , use export-csv create output file if want file open nicely in excel.


edit: today lucky day. had written , open in 1 of ise tabs, i'll post it.

get-content .\pclist.txt | foreach-object {      $cs = get-wmiobject win32_computersystem -computername $_     $bios = get-wmiobject win32_bios -computername $_      $props = @{         name = $cs.name         model = $cs.model         serialnumber = $bios.serialnumber     }      new-object psobject -property $props  } | select name,model,serialnumber |         export-csv .\output.csv -notypeinformation


i highly recommend using foreach-object loops when trying output csv. type of loop easier (imho) when exporting.




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file