Last active
March 28, 2018 02:56
-
-
Save tostka/cf696eeea81a083526ad441714f4465a to your computer and use it in GitHub Desktop.
Remote drivespace reporting script to monitor and report on the available Transaction Log space on Exchange servers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# TRIMMED gist, see full script for details #> | |
#*---------------------------v Function Get-TLogSpaceRegion v--------------------------- | |
Function Get-TLogSpaceRegion ($ExTargVers,$SiteName) { | |
If ($bDebug -eq $TRUE) { | |
Write-Host ("Get-TLogSpaceRegion,ExTargVers: " + $ExTargVers) | |
} | |
Write-Host -ForegroundColor White ("Site: " + $SiteName) | |
if ($SiteName -eq 'NONE') { | |
Clear-Variable outfile -ErrorAction SilentlyContinue | |
Write-Host -ForegroundColor Yellow ("No Ex2010 in site: " + $SiteName + " skipping...") | |
$SmtpBody +="No Ex2010 in site: " + $SiteName + " skipping..." | |
#$attachment = $ScriptDir + "logs\" + $ScriptNameNoExt + "-" + $targServer + "-" + $TimeStampNow + ".txt" | |
#$SMTPSubj= ("Daily Rpt: "+ (Split-Path $attachment -Leaf) + " " + [System.DateTime]::Now) | |
$SMTPSubj= ("Daily Rpt: Site:" + $SiteName + " " + " ExRev: " + $ExTargVers + ", " + [System.DateTime]::Now) | |
Send-EmailNotif | |
} Else { | |
$sMsg = "Checking Exch vers " + $ExTargVers | |
if ($ExClstr -ne $null) {$sMsg += " (" + $ExClstr + " replic)" } | |
$sMsg += " servers in site " + $SiteName | |
Write-Host -ForegroundColor green ($sMsg) | |
# $ExTargVers [8|14],$SiteName as per above | |
If ($bDebug -eq $TRUE) { | |
#write-host "ServersMbxNAF: " $ServersMbxNAF | |
write-host "SiteName: " $SiteName | |
write-host "ExTargVers: " $ExTargVers | |
} # if-block end | |
# NA|EU|AU | |
switch ($SiteName) | |
{ | |
"NA" { | |
If ($bDebug -eq $TRUE) { write-host "US BLOCK"} | |
switch ($ExTargVers.ToSTring()){ | |
"2007" {$targServers=$ServersMbxNA} | |
"2010" {$targServers=$ServersMbxNA} | |
} # switch block end | |
} # switch entry end | |
"EU" {$targServers=$ServersMbxEU} | |
"AU" {$targServers=$ServersMbxAU} | |
} # switch block end | |
If ($bDebug -eq $TRUE) { write-host "targServers: " $targServers } | |
if ($targServers.Count -eq $null) { | |
Write-Host -ForegroundColor Yellow ("No matching servers in site " + $SiteName) | |
} else { | |
Write-Host ("targServers count: " + $targServers.Count) | |
If ($bDebug -eq $TRUE) {$targServers} | |
foreach ($targServer in $targServers) { | |
Write-Host ("Time: " + (get-date).ToString("HH:mm:ss")) | |
$outransfile=$ScriptDir + "logs\" + $ScriptNameNoExt + "-" + $targServer + $TimeStampNow + "-trans.txt" | |
if (test-path $outransfile) {remove-item $outransfile -force } | |
write-host -ForegroundColor Yellow ("`$targServer: " + $targServer) | |
Clear-Variable outfile -ErrorAction SilentlyContinue | |
$attachment = $ScriptDir + "logs\" + $ScriptNameNoExt + "-" + $targServer + "-" + $TimeStampNow + ".txt" | |
if (test-path $attachment) {write-host -foregroundcolor yellow "removing existing" $attachment ; remove-item $attachment -force } | |
write-host ("outfile: " + $attachment) | |
$SmtpBody += ('-' * 50) | |
$SmtpBody +=$targServer + " pass started," + (((get-date).ToString("HH:mm:ss"))) | |
$SMTPSubj= ("Daily Rpt: "+ (Split-Path $attachment -Leaf) + " " + [System.DateTime]::Now) | |
if (($targServer).ToUpper() -match '(?i:((SITE|SITEB)MSXX\d))') { | |
# Volume-mount point; hose with luns with names with distinct substrings to target | |
#$sExcCmd = "Get-Wmiobject -query 'select name,driveletter,capacity,freespace from win32_volume where drivetype=3 AND driveletter=NULL' -computer " + $targServer | |
$sExcCmd = "Get-Wmiobject -query 'select name,driveletter,capacity,freespace from win32_volume where drivetype=3' -computer " + $targServer | |
$sExcCmd = $sExcCmd + " | where {(`$_.Name -match '(?i:((E|F):\\(SITE|SITE).*MAIL0\d\\))')}" | |
} elseif (($targServer).ToUpper() -match '(?i:((SITE|SITE)MS64\d))' ) { | |
# pull the drive letter filter (which will come back F:; name comes back F:\ | |
$sExcCmd = "Get-Wmiobject -query 'select name,driveletter,capacity,freespace from win32_volume where drivetype=3' -computer " + $targServer | |
# regex e-h: | |
$sExcCmd = $sExcCmd + " | where {(`$_.Name -match '(?i:((E|F|G|H):\\))')}" | |
} # if-block end | |
# 12:00 PM 8/30/2013 sub in win32_volume code, which supports capacity attrib (but doesn't appear to return freespace as % (has to be calcd) | |
$sExcCmd = $sExcCmd + " | Sort Name | Select Name,@{Name='VolSize(gb)';Expression={[decimal]('{0:N1}' -f(`$_.capacity/1gb))}},@{Name='Freespace(gb)';Expression={[decimal]('{0:N1}' -f(`$_.freespace/1gb))}},@{Name='Freespace(%)';Expression={'{0:P2}' -f((`$_.freespace/1gb)/(`$_.capacity/1gb))}}" | |
# 10:57 AM 8/28/2013 fresh tee use, putting tee inside the invoked string | |
$sExcCmd=$sExcCmd + " | tee -FilePath $attachment" | |
If ($bDebug -eq $TRUE) { | |
write-host "sExcCmd at Invoke:" | |
$sExcCmd | |
} | |
Invoke-Expression $sExcCmd | |
If ($bDebug -eq $TRUE) { | |
Write-Host -ForegroundColor Yellow "Pass completed" | |
Write-Host "---" | |
} | |
else { | |
} | |
<# TRIMMED #> | |
} # server for-loop end | |
} # if-block end NoServers test | |
} # if-block end Vers/Site exclusion | |
<# TRIMMED #> | |
} | |
#*---------------------------^ End Function Get-TLogSpaceRegion ^--------------------------- | |
<# TRIMMED #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment