Class Challenge 2
blah
$foo = "." [wmi]"\\$foo\root\cimv2:Win32_LogicalDisk.DeviceID='C:'" | Select-Object __SERVER, deviceid, size, freespace
Format output to GB
[wmi]"\\$foo\root\cimv2:Win32_LogicalDisk.DeviceID='C:'" | Select-Object __SERVER, deviceid, ` @{"Label"="Size GB";Expression={[int]($_.Size/1gb)}}, ` @{"Label"="Freespace GB";Expression={[int]($_.Freespace/1gb)}}
$strtextfile = Get-Content -Path "C:\Temp\Servers.txt" foreach ($server in $strtextfile) { $item = [wmi]"\\$server\root\cimv2:Win32_LogicalDisk.DeviceID='C:'" | Select-Object __SERVER, deviceid, ` @{"Label"="Size GB";Expression={[int]($_.Size/1gb)}}, ` @{"Label"="Freespace GB";Expression={[int]($_.Freespace/1gb)}} #Write-host "Drive $($item.DeviceID) on Computer $server has $($item.freespace)" Write-host "Drive $item.DeviceID on Computer $server has $($item.freespace)" }
$strtextfile = Get-Content -Path "C:\Temp\Servers.txt" foreach ($server in $strtextfile) { $wmiobject = get-wmiobject -class win32_logicalDisk -Computername $server -filter "Drivetype=3" | Select-object DeviceID,freespace,size #Get-Wmiobjec returns a collection Foreach ($item in $wmiobject) { Write-host "Drive $($item.DeviceID) on Computer $server has $([int64]($item.freespace/1gb))" } }