HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
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
}