Hi Folks,
Need your expert advice here.
Below is the code that I wrote to get the Size and Free space on C and E drives from multiple servers which I would input via a text file.
$Computers = Get-Content -Path c:\temp\servers.txt
foreach ($Computer in $Computers)
{
Get-WmiObject -ComputerName $Computer -Class win32_logicaldisk |
where {$_.DeviceID -eq "C:" -or $_.DeviceID -eq "E:"} |
Select Pscomputername, DeviceID, @{n='Size(GB)'; e={($_.Size/1gb -as [int])}}, @{n='Free(GB)'; e={($_.FreeSpace/1GB) -as [int]}}
}
Below is the output that I receive.
PSComputerName DeviceID Size(GB) Free(GB) -------------- -------- -------- -------- Server1 C: 60 31 Server2 C: 50 30 Server3 E: 40 18
Now, I want the Size and Free Space values (Eg. 60 and 31 in first line) to have ‘Gb’ string with them (Eg. 60Gb and 31Gb).
How to get the output in that format?