Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Script to monitor free space on mapped logical disk.

$
0
0

That script works correctly:

 

"

$mythreshold = 1000GB

$computerName = "mycomputer.domain.com"

 

Get-WmiObject -class "win32_mappedlogicaldisk" -namespace "root\CIMV2" -computername "$computerName" | select-object deviceid, freespace, providername | foreach { 

    if ($_.freespace -lt $mythreshold) 

    {

        $amount_GB = $_.FreeSpace/1024000000

        $body = " Drive: " + $_.deviceid + " GigaBytes: " + $amount_GB + " Share: " + $_.ProviderName

        $body

    }   

    }

"

and gives a result:

Drive: U: GigaBytes: 394.6386 Share: \\share1\data_2012

 Drive: V: GigaBytes: 1031.312976 Share: \\share1\data_2011

 Drive: W: GigaBytes: 1041.972064 Share: \\share2\data_2012

 Drive: X: GigaBytes: 5.200416 Share: \\share2\data_2011

 Drive: Y: GigaBytes: 339.622568 Share: \\share3\data_2012

 Drive: Z: GigaBytes: 451.74764 Share: \\share3\data_2011

 Drive: O: GigaBytes: 60.771092 Share: \\share4\data_2012

Two questions:

 

1. How format results to see $amount_GB rounded to total (61 insteed of 60.771092 in last line):

Drive: O: GigaBytes: 61 Share: \\share4\data_2012

2. I want display only that values which contains "2012" in share name, when corrected "if line" in script to:

"

  if (($_.freespace -lt $mythreshold) -and ($_.ProviderName -contains "2012"))

"

I get nothing as result, if change to:

"

  if (($_.freespace -lt $mythreshold) -and ($_.ProviderName -eq "\\share2\data_2012"))

"

I get nothing too.

Where is an error in syntax with that script (for -eq and -contains conditions) ?


Viewing all articles
Browse latest Browse all 6937

Trending Articles