powershell - How to extract server information -


objective: how extract server information?

for each server name listed in servers.txt, following information (in format):

server name, ip address, os name, total physical memory, processors, each drive letter , size, system model

comma separated , new line each server.

below powershell code. can guys give hint on why not work? why error new-object statement?

foreach ($computername in (get-content -path .\servers.txt)) {   $hashprops = @{     'thostname' = get-wmiobject win32_computersystem -computername $computername | select-object -expandproperty name     'tip' = [system.net.dns]::gethostaddresses($computername)     'tos' = get-wmiobject -computername $computername -class win32_operatingsystem | select-object -expandproperty caption     'tmemory' = get-wmiobject win32_physicalmemory | measure-object -property capacity -sum | foreach { "$("{0:n2}" -f ( $_.sum/1gb ) )" }     'tcpu' = get-wmiobject win32_processor | select-object name, numberofcores     'tdisks' = get-wmiobject win32_logicaldisk | foreach { "$($_.deviceid) $("{0:n2}" -f ( $_.size/ 1gb ) )" }     'tsysmodel' = get-wmiobject win32_computersystem | select-object model   }   new-object -typename psobject -property $hashprops |   convertto-csv -notypeinformation | out-file -append .\output.csv } 

i open other approach, if easier.

have verified each of lines return want?

i threw ise , works fine:

$f = gwmi win32_computersystem | select name,model,totalphysicalmemory $hash = @{     'name' = $f.name     'model' = $f.model     'memory' = $("{0:n2}" -f ( $f.totalphysicalmemory/1gb ) ) } new-object -typename psobject -property $hash | convertto-csv -notypeinformation | out-file -append .\test.csv 

also, if want properties appear in specific order in csv, take additional magic, otherwise they're put in alphabetically.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -