Powershell - diskspace query


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="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...
Who is Participating?
footechConnect With a Mentor Commented:
Can you check the minus sign/hyphen (the second one) in the Used Space calculated property?  It appears to be a long dash instead.
ISD-PLCAuthor Commented:
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.
ISD-PLCAuthor Commented:
Thanks very much much appreciated.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.