none
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

    Saturday, May 21, 2016 1:36 PM

Answers

All replies