Quantcast
Channel: THWACK: All Content - Server & Application Monitor
Viewing all articles
Browse latest Browse all 12281

Powershell Script Output Problem

$
0
0

Been messing with this for at least an hour and I cannot for the life of me get the script output.  I've shortened the number to a "int".  I've tried casting to int.  I've tried different variations of the output.  Made sure to include unique name in the output. Tried to just write the output from my FreeSpaceCheck function.. Nothing work..... please assist

 

 

#*=============================================

#* FUNCTION LISTINGS

#*=============================================

# Function: Get-AllVolumesWithNoDriveLetter

# Created: [2/24/2014]

# Arguments:

# =============================================

# Purpose: Detects x86 and x64 and queries software

# registry hive for installed applications on the server

#

# =============================================

function GetAllVolumesWithNoDriveLetter

    {     

    # Using try so that we can catch any errors encountered with script to report back to solarwinds

    try

        {

        #Query all volumes with no letter and assign to variable.

        $global:drivesNoLetter = gwmi -Query "Select * from Win32_Volume where DriveType=3 AND DriveLetter is NULL"

 

        }

    catch

        {

        #Output errors if necessary

        $global:errors += "Error querying drives on server: " + $_.Exception.Message;

        }

    }

# =============================================

# End of FindDrivesLowOnSpace function

# =============================================

 

#*=============================================

# Function: FindDrivesLowOnSpace

# Created: [2/27/2014]

# Arguments:

# =============================================

# Purpose: Goes through list of detected volumes and performance percentage calculation

#          If drive exceeds threshold then it will report back to Solarwinds Application Monitor#

# =============================================

 

function FindDrivesLowOnSpace

{

    try

    {

        $driveCounter =0;

        foreach($drive in $global:drivesNoLetter)

        {

            $percentage = ($drive.FreeSpace/$drive.Capacity)*100

#Debugging comments - Uncomment to use

            #write-host $percentage

            #write-host $drive.Name

            $driveName = $drive.Name;

            if ($percentage -le $global:threshold)

            {

            # We've found a system with less than 10 percent available - add to report

                $OutputObj  = New-Object -Type PSObject;

                $OutputObj | Add-Member -Name "Message" -MemberType NoteProperty $driveName

                $OutputObj | Add-Member -Name "Statistic" -MemberType NoteProperty $percentage;

                $global:results += $OutputObj;               

                $driveCounter +=1;

            }

 

        }

    }

    catch

    {

    #Output errors if necessary

    $global:errors += "Error calculating drive space: " + $_.Exception.Message;

    }

}

 

   

 

 

#*================================================

#* SCRIPT BODY

#*================================================

$global:threshold = $args[0];

$global:results=@();

$global:drivesNoLetter=@();

$global:errors=@();

 

# Query all volumes on server that have no drive letter

GetAllVolumesWithNoDriveLetter;

 

#Debugging comment - uncomment to use

 

#write-host $global:drivesNoLetter.Count

#break

 

#Interate through all drives found and determine if they exceed thresholds sent via script argument

FindDrivesLowOnSpace;

 

 

 

 

# Fist we need to verify there isn't more than 10 results to report - If so we are missing data

if ($global:results.Count -gt 10)

    {

    # Sigh.. this server is in bad shape!

    Write-Host "Message: More than 10 drives out of space, please investigate";

    #break

    }

 

 

#Make sure there are no errors if so we need to report them"

if($global:errors.Count >0)

    {

    # Stuff happened

    foreach($error in $global:errors)

        {

        Write-Host "Message: $error";

        }

 

    }

 

# Report results of query

 

$counter=0;

$results = $global:results

foreach ($result in $global:results)

    {

     $shortNum = [Math]::Truncate($result.Statistic);

     write-host "Message.Name$counter :"$result.Message

     write-host "Statistic.Name$counter :"$shortNum

   

    }

 

Exit(0)


Viewing all articles
Browse latest Browse all 12281

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>