bryan oakley-wiggins
asked on
Powershell mount point freespace email
Hi
*** Environment ***
Windows 2003 AD
Exchange 2007
I have the following code (to follow) that Iam working on, to query my mount points and report back freespace/capacity.
I would like to be able to include some logic to give me also the freespace in %, I.e
Mount Point freeSpace (GB) capacity Percentfree
----------- -------------- -------- -------------
M:\ 0.07 0.10 %x
M:\SG1\Logs\ 0.97 1.00 %x
M:\SG1\Database\ 2.86 2.90 %x
M:\SG2\Logs\ 0.97 1.00 %x
M:\SG2\Database\ 2.86 2.90 %x
The PoSh code is:
forEach ($server in (Get-Content allservers.txt)) {
Get-WmiObject Win32_volume -ComputerName $server | where {$_.caption -like "M:\*"} | `
select @{name="Mount Point";expression={$_.capt ion}},@{na me="freeSp ace (GB)";e={($_.freespace/1GB ).tostring ("F02")}}, `
@{name="capacity";expressi on={($_.Ca pacity/1GB ).tostring ("F02")}} | ft -autosize | out-file "$server.txt"
}
This all works fine, as I say I would like to get a % conversion done also (if possible) and then I would like to get this sent by email...
Any pointers appreciated..!
Cheers
Bry
*** Environment ***
Windows 2003 AD
Exchange 2007
I have the following code (to follow) that Iam working on, to query my mount points and report back freespace/capacity.
I would like to be able to include some logic to give me also the freespace in %, I.e
Mount Point freeSpace (GB) capacity Percentfree
----------- -------------- -------- -------------
M:\ 0.07 0.10 %x
M:\SG1\Logs\ 0.97 1.00 %x
M:\SG1\Database\ 2.86 2.90 %x
M:\SG2\Logs\ 0.97 1.00 %x
M:\SG2\Database\ 2.86 2.90 %x
The PoSh code is:
forEach ($server in (Get-Content allservers.txt)) {
Get-WmiObject Win32_volume -ComputerName $server | where {$_.caption -like "M:\*"} | `
select @{name="Mount Point";expression={$_.capt
@{name="capacity";expressi
}
This all works fine, as I say I would like to get a % conversion done also (if possible) and then I would like to get this sent by email...
Any pointers appreciated..!
Cheers
Bry
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi Subsun
well, thanks for the pointer - bit of tweaking and it worked for me..!
(Chris-Dent - he's a genius, )
Thanks for that...
For anyone intersted, here's the full code I use:
# this section gets the server from a list
foreach ($server in (Get-Content allservers.txt)) {
Get-WmiObject Win32_Volume -ComputerName $server | where {$_.caption -like "M:\*"} | `
# this section does the formatting and percentage used calculation
Format-Table `
@{l="Server";e={$_.server} }, `
@{l="Drive Letter";e={$_.caption}}, `
@{l="Free Space on Disk (GB)";e={"{0:n2}" -f ($_.freespace/1gb)}}, `
@{l="Total Disk Space (GB)";e={"{0:n2}" -f ($_.Capacity/1gb).toString ("F02")}}, `
@{l="Percentage Used";e={ "{0:P2}" -f (1 - ([Int64]$_.FreeSpace / [Int64]$_.Capacity)) }} | Out-File "c:\scripts\testing\MOUNTS 1.log"
}
# this section picks up the file and emails it to addressees listed
$file = "c:\scripts\testing\LOG.lo g"
$smtpServer = "YourSMTPServer"
$msg = new-object Net.Mail.MailMessage
$att = New-Object Net.Mail.Attachment($file)
$smtp = New-Object Net.Mail.SmtpClient($smtpS erver)
$Today = Get-Date
$msg.From = "user@company.int"
$msg.To.Add("user@company. int")
$msg.Subject = "subject here"
$msg.Body = "body contents here"
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
well, thanks for the pointer - bit of tweaking and it worked for me..!
(Chris-Dent - he's a genius, )
Thanks for that...
For anyone intersted, here's the full code I use:
# this section gets the server from a list
foreach ($server in (Get-Content allservers.txt)) {
Get-WmiObject Win32_Volume -ComputerName $server | where {$_.caption -like "M:\*"} | `
# this section does the formatting and percentage used calculation
Format-Table `
@{l="Server";e={$_.server}
@{l="Drive Letter";e={$_.caption}}, `
@{l="Free Space on Disk (GB)";e={"{0:n2}" -f ($_.freespace/1gb)}}, `
@{l="Total Disk Space (GB)";e={"{0:n2}" -f ($_.Capacity/1gb).toString
@{l="Percentage Used";e={ "{0:P2}" -f (1 - ([Int64]$_.FreeSpace / [Int64]$_.Capacity)) }} | Out-File "c:\scripts\testing\MOUNTS
}
# this section picks up the file and emails it to addressees listed
$file = "c:\scripts\testing\LOG.lo
$smtpServer = "YourSMTPServer"
$msg = new-object Net.Mail.MailMessage
$att = New-Object Net.Mail.Attachment($file)
$smtp = New-Object Net.Mail.SmtpClient($smtpS
$Today = Get-Date
$msg.From = "user@company.int"
$msg.To.Add("user@company.
$msg.Subject = "subject here"
$msg.Body = "body contents here"
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
ASKER
forEach ($server in (Get-Content allservers.txt)) {
Get-WmiObject Win32_volume -ComputerName $server | where {$_.caption -like "M:\*"} | `
select @{name="Mount Point";expression={$_.capt
@{name="capacity";expressi
}
$file = "c:\scripts\testing\server
$smtpServer = "mailrelay"
$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($smtpS
$Today = Get-Date
$msg.From = "ServerEngineering@company
$msg.To.Add("user@company.
$msg.Subject = "$Today Today's VMP check - DO NOT REPLY TEST TEST TEST"
$msg.Body = "$Today The daily VMP check TEST TEST TEST"
$msg.Body = $file
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()