Posts

Showing posts from May, 2022

Send email alert if Reboot or shutdown a Server with Powershell

Image
Présentation This script allows to send a status mail when a server restarts or stops. All actions are logged to C:\Logs. Github Link :  https://github.com/ChrisMogis/Scripts/blob/main/Alert_State_Server.ps1 Exécution command line for reboot status :  powershell.exe -executionpolicy ByPass -file .\ScriptName.ps1 -Option Reboot Exécution command line for shutdown status :  powershell.exe -executionpolicy ByPass -file .\ScriptName.ps1 -Option Shutdown #Script Parameters Param ( [Parameter(Mandatory= $true )] [ValidateSet( "Reboot" , "Shutdown" )] [String[]] $Option ) #Function create Log folder     Function CreateLogsFolder {     If (!( Test-Path C:\Logs))     {     New-Item -Force -Path "C:\Logs\" -ItemType Directory } else {     Write-Host "The folder " C:\Logs\ " already exists !"     } } #Create Log Folder     CreateLogsFolder #Declaration of script variables     ...

Monitor a server hard drives with Powershell

Image
Monitor a server hard drives with Powershell Script  This script is used to monitor the disk space of a server and to send an alert email when the remaining disk space reaches the limit set by the administrator. Github Link :  https://github.com/ChrisMogis/MonitoringFreeHardDriveSpace/blob/main/FreeSpaceHardDrive.ps1  #Function create Log folder     Function CreateLogsFolder {     If (!( Test-Path C:\Logs))     {     New-Item -Force -Path "C:\Logs\" -ItemType Directory } else {     Write-Host "The folder " C:\Logs\ " already exists !"     } } #Create Log Folder     CreateLogsFolder #Declaration of script variables $Client = "Client Name" $ListDisk = Get-CimInstance -Class Win32_LogicalDisk | where { $_ .DriveType -eq "3" } $Server = (Get-CimInstance -ClassName Win32_ComputerSystem).Name $SetMinSizeLimit = 50 GB; $LogPath = "C:\Logs\CheckHardDriveFreeSpace.log" $Date = Get-Date #Scan...