How to merge powershell scripts to get disk used space, disk free space, cpu utilization and memory utilization in one csv file? -


i have separate code disk space details, how can merge these 2 program disk usage, disk free space , cpu utilization output in 1 csv file.

    get-wmiobject -class win32_logicaldisk -computername "phatuggikadabba" |  where-object {$_.drivetype -eq 3} | select-object deviceid, description,`     @{"label"="disksize(gb)";"expression"={"{0:n}" -f ($_.size/1gb) -as [float]}}, `     @{"label"="freespace(gb)";"expression"={"{0:n}" -f ($_.freespace/1gb) -as [float]}} |     export-csv 'd:\code\diskspaceusage .csv' -notype 

i have 1 more file written in powershell gives cpu utilization, memory usage , users

    gc d:\serverlist.txt | % { $comp = $_ if (test-connection $comp -quiet){ $luser = (get-wmiobject -class win32_process -filter "name='explorer.exe'" -computername $comp | % {$_.getowner().user} | sort-object -unique) -join "," $mem = gwmi -class win32_operatingsystem -computername $comp       new-object psobject -property @{       server = $comp       "cpu usage" = "$((gwmi -computername $comp win32_processor | measure-object -property loadpercentage -average).average) %"       "memory usage" = "$("{0:n2}" -f ((($mem.totalvisiblememorysize - $mem.freephysicalmemory)*100)/ $mem.totalvisiblememorysize)) %"       "total freespace" = "$("{0:n2}" -f ((get-wmiobject -class win32_logicaldisk -computername $comp -filter "drivetype = '3'" | measure-object -property freespace -sum).sum /1gb)) gb"       "logged users" = $luser       } } else{ "" | select @{n="server";e={$comp}},"cpu usage","memory usage","total freespace","logged users" } }| select server,"cpu usage","memory usage","total freespace","logged users" | export-csv "d:\code\report$(get-date -f dd_mm_yyy_hhmm).csv" 

output both codes :

1.

deviceid    description        disksize(gb)     freespace(gb)** c:          local fixed disk   230.21             67.33  d:          local fixed disk   222.94             79.15  

2.

server    cpu usage  memory usage   total freespace logged users** boss'pc    48%        48.21%           146.48 gb     boss 

in order this, create array, , load custom objects, each of has properties store in row.

$script:array = @() $computerlist |% {   $ob = new-object system.object   function1 {     $ob | add-member -type noteproperty -name cpu -value $_.cpu   }   function2 {     $ob | add-member -type noteproperty -name diskuse -value $_.disk   }   $script:array += $ob } $script:array | export-csv file.csv 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -