File: D:/bin/scripts/PowerShell/Utils.ps1
# (SS,14/11/2023) PowerShell Utils.ps1
# For free drive space useful help from https://adamtheautomator.com/powershell-get-disk-space/
function GetFreeDriveSpaceInfo {
param (
$MinFreeSpaceGB,
$Drives
)
#$MIN_FREE_SPACE = 30
$NEW_LINE = "`r`n"
$result = $NEW_LINE
$result += "----------------$NEW_LINE"
$result += "FREE DRIVE SPACE" + $NEW_LINE
$result += "----------------$NEW_LINE"
#$result += GetFreeDriveSpaceCheckInfo C $MinFreeSpaceGB
#$result += $NEW_LINE
#$result += GetFreeDriveSpaceCheckInfo D $MinFreeSpaceGB
#$result += $NEW_LINE
#$result += GetFreeDriveSpaceCheckInfo E $MinFreeSpaceGB
$Drives.Split(",") | ForEach-Object {
$Drive = ($_).Trim()
$result += GetFreeDriveSpaceCheckInfo $Drive $MinFreeSpaceGB
$result += $NEW_LINE
}
return $result
}
function GetFreeDriveSpaceCheckInfo {
param (
$Drive,
$MinGB
)
$Free = GetFreeDriveSpace $Drive
if ($Free -lt $MinGB) {
$Status = $Status = "LOW"
}
else {
$Status = $Status = "OK"
}
$Result = "Drive $Drive" + ": $Free GB - $Status"
return $Result
}
function GetFreeDriveSpace {
param (
$Drive
)
#Get-PSDrive $Drive
#Write-Output $Str
return [math]::Round((Get-PSDrive $Drive).Free / 1GB, 2)
}
function SendEmail {
param (
[string]$Subject,
[string]$Body,
[int]$Priority
)
Send-MailMessage -From 'ITP Web Server <server@itpartnership.com>' -To 'surinder@itpartnership.com' -Subject $Subject -SmtpServer 'localhost' -Priority $Priority -Body $Body
}