Link to home
Start Free TrialLog in
Avatar of ISD-PLC
ISD-PLCFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Powershell - diskspace query

Hi,

I am trying to create a powershell script to query servers and return the drive size and used space but I'm runing into issues..

current script is (attached as well to get round cut/paste issue)

$servers = Get-Content C:\scripts\diskspace\servers.txt
 
$DriveSize = foreach($server in $servers){
 Get-WMIObject Win32_LogicalDisk -filter "DriveType=3" -computer $server `
 | Select SystemName,DeviceID,VolumeName,`
 @{Name="Size(GB)";Expression={[decimal]("{0:N1}"-f($_.size/1gb))}},`
 @{Name="Used Space(GB)";Expression={[decimal]("{0:N1}"-f(($_.size/1gb)-($_.freespace/1gb)))}},`
 @{Name="Used Space(%)";Expression={"{0:P2}"-f((($_.size/1gb)–($_.freespace/1gb))/($_.size/1gb))}}
 }
$DriveSize | Out-GridView -Title 'Drive Size'
$DriveSize | Export-CSV C:\scripts\diskspace\servers\drive.csv -NoType


Im getting errors related to missing terminators. I want to get this work so I can move on to adding cpu/ram info.

Thanks for any pointers...
DiskSpaceReport4.txt
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ISD-PLC

ASKER

well spotted that fixed it... that has been driving me nuts for ages!

Now to work out how to add a CPU and RAM query....
Luckily attaching the script as you did made it very easy to spot.
Avatar of ISD-PLC

ASKER

Thanks very much much appreciated.