Answered by:
Need the syntax for c drive free percentage on servers - Using power shell

Question
-
Hi Friends,
I could find some ps script with gui option for server health check. It has its grid view and displays server parameters like uptime, last boottime, Service pack etc. So I was trying to add c drive free percentage parameter also into this. I have attached the parameters syntax part below and it contains my syntax for c drive free percentage as well, but didn't work. Since am very new to PS i have failed to make it successful :(
Request you to help me with your ideas to fix it (I have hashed my syntax)
Please feel free to revert for any questions
if ($os) {
#clear OS if it has a left over value
Clear-Variable os
}
$os=Get-OS $computer
if ($os) {
$lastboot=$os.ConvertToDateTime($os.lastbootuptime)
Write-Debug "Adding $lastboot"
uptime=((get-date) - ($os.ConvertToDateTime($os.lastbootuptime))).tostring()
Write-Debug "Adding $uptime"
#$HotFix=Get-HotFix | Select-Object installedOn -last 1 | Sort-Object -Property installedOn -Des
#Write-Debug "Adding $HotFix
#$drive=Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" |
#Select-object @{Expression = {“{0:N2}” -f (($_.FreeSpace / $_.Capacity)*100) } }
#Write-Debug "Adding $drive"
$osname=$os.Caption
Write-Debug "Adding $osname"
$servicepack=$os.CSDVersion
Write-Debug "Adding $servicepack"
$obj | Add-Member Noteproperty OS $osname
$obj | Add-Member Noteproperty ServicePack $servicepack
$obj | Add-Member Noteproperty Uptime $uptime
$obj | Add-Member Noteproperty LastBoot $lastboot
#$obj | Add-Member Noteproperty Last Windows update $HotFix
#$obj | Add-Member Noteproperty System Drive $drive
}
else {
Write-Debug "Setting properties to N/A"
$obj | Add-Member Noteproperty OS "N/A"
$obj | Add-Member Noteproperty ServicePack "N/A"
$obj | Add-Member Noteproperty Uptime "N/A"
$obj | Add-Member Noteproperty LastBoot "N/A"
#$obj | Add-Member Noteproperty Last Windows update "N/A"
#$obj | Add-Member Noteproperty System Drive "N/A"
}
}
else {
Write-Debug "Ping failed"
Write-Debug "Setting properties to N/A"$obj | Add-Member Noteproperty Pinged "No"
$obj | Add-Member Noteproperty IP "N/A"
$obj | Add-Member Noteproperty OS "N/A"
$obj | Add-Member Noteproperty ServicePack "N/A"
$obj | Add-Member Noteproperty Uptime "N/A"
$obj | Add-Member Noteproperty LastBoot "N/A"
#$obj | Add-Member Noteproperty Last Windows update "N/A"
#$obj | Add-Member Noteproperty System Drive "N/A"
}
#Add the object to griddata
Write-Debug "Adding `$obj to `$griddata"
$griddata+=$obj- Moved by Dave PatrickMVP Saturday, May 21, 2016 2:15 PM
Saturday, May 21, 2016 1:36 PM
Answers
-
I'd try them over here.
https://social.technet.microsoft.com/Forums/office/en-US/home?forum=winserverpowershell
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Mike Laughlin Monday, May 23, 2016 12:26 PM
- Marked as answer by Just Karl Wednesday, June 8, 2016 8:52 PM
Saturday, May 21, 2016 2:14 PM
All replies
-
I'd try them over here.
https://social.technet.microsoft.com/Forums/office/en-US/home?forum=winserverpowershell
Regards, Dave Patrick ....
Microsoft Certified Professional
Microsoft MVP [Windows Server] Datacenter Management
Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.- Proposed as answer by Mike Laughlin Monday, May 23, 2016 12:26 PM
- Marked as answer by Just Karl Wednesday, June 8, 2016 8:52 PM
Saturday, May 21, 2016 2:14 PM -
Hi
Use following command.
gwmi win32_volume -Filter 'drivetype = 3' | select driveletter, label, @{LABEL=’GBfreespace';EXPRESSION={$_.freespace/1GB} }
Saturday, May 21, 2016 2:36 PM -
Sorry for my late reply as i was hospitalised due to some illness.
Im so sorry... I will move this to official scripting forum
Sunday, May 29, 2016 5:36 AM