diff --git a/Monitor-PrivilegedGroupChanges.ps1 b/Monitor-PrivilegedGroupChanges.ps1 new file mode 100644 index 0000000..b88402f --- /dev/null +++ b/Monitor-PrivilegedGroupChanges.ps1 @@ -0,0 +1,41 @@ +# Monitors any changes to privileged groups + +Function Get-PrivilegedGroupChanges { + Param( + $Server = "localhost", + $Hour = 24 + ) + + $ProtectedGroups = Get-ADGroup -Filter 'AdminCount -eq 1' -Server $Server + $Members = @() + + ForEach ($Group in $ProtectedGroups) { + $Members += Get-ADReplicationAttributeMetadata -Server $Server ` + -Object $Group.DistinguishedName -ShowAllLinkedValues | + Where-Object {$_.IsLinkValue} | + Select-Object @{name='GroupDN';expression={$Group.DistinguishedName}}, ` + @{name='GroupName';expression={$Group.Name}}, * + } + $Members | + Where-Object {$_.LastOriginatingChangeTime -gt (Get-Date).AddHours(-1 * $Hour)} +} + +$ListOfChanges = Get-PrivilegedGroupChanges + +foreach($Change in $ListOfChanges){ + if($Change.LastOriginatingDeleteTime -gt "1-1-1601 01:00:00"){ $ChangeType = "removed" } + else { $ChangeType = "added"} + write-host "$($Change.groupname) has been edited. $($Change.AttributeValue) has been $ChangeType" +} + +if($ListOfChanges -eq $Null){write-host "GroupChanges=Healthy"} +elseif($ListOfChanges.count -gt 1){ + write-host "GroupChanges=Multiple groups have been changed. Please check diagnostic data" + exit 1 +} +else{ + if($listofchanges.LastOriginatingDeleteTime -gt "1-1-1601 01:00:00"){ $ChangeType = "removed" } + else { $ChangeType = "added"} + write-host "GroupChanges=$($ListOfChanges.groupname) has been edited. $($listofchanges.AttributeValue) has been $ChangeType" + exit 1 +} diff --git a/Monitor-R4Backup.ps1 b/Monitor-R4Backup.ps1 new file mode 100644 index 0000000..8e19663 --- /dev/null +++ b/Monitor-R4Backup.ps1 @@ -0,0 +1,20 @@ +# Monitors wether an R4 Full backup has run in the last day or a database backup in the last 18 hours + +try{ + $fullBackupLog = Get-EventLog -LogName Application -Source MSSQLSERVER -Message "*FullBackup*" -After (get-date).AddDays(-1) + $filteredFullBackupLog = ForEach ($event in $fullBackupLog){if ($event.EventID -eq 18264){$event}} +} +catch{$filteredFullBackupLog = $null} + +try { + $dbBackupLog = Get-EventLog -LogName Application -Source MSSQLSERVER -Message "*DBBackup*" -After (get-date).AddHours(-18) + $filteredDbBackupLog = ForEach ($event in $dbBackupLog){if ($event.EventID -eq 18264){$event}} +} +catch {$filteredDbBackupLog = $null} + + +if (($filteredFullBackupLog -ne $null) -and ($filteredDbBackupLog -ne $null)){Write-Host "Both Backups have Run"; exit 0} +elseif (($filteredFullBackupLog -eq $null) -and ($filteredDbBackupLog -ne $null)){Write-Host "Full Backup has NOT Run"; exit 1} +elseif (($filteredFullBackupLog -ne $null) -and ($filteredDbBackupLog -eq $null)){Write-Host "Database Backup has NOT Run"; exit 1} +elseif (($filteredFullBackupLog -eq $null) -and ($filteredDbBackupLog -eq $null)){Write-Host "Both Backups have NOT Run"; exit 1} +else {Write-Host "Error"; exit 1} diff --git a/Monitor-WindowsFirewallState.ps1 b/Monitor-WindowsFirewallState.ps1 new file mode 100644 index 0000000..fc5a9e1 --- /dev/null +++ b/Monitor-WindowsFirewallState.ps1 @@ -0,0 +1,22 @@ +# Monitors the state of windows firewall + +function Write-Diag { + foreach ($Message in $Messages) { $Message } +} + +$FirewallState = @() + +$FirewallProfiles = Get-NetFirewallProfile | Where-Object {$_.Enabled -eq $false} + +If($FirewallProfiles){$FirewallState += "$($FirewallProfiles.name) Profile is disabled"} + +$FirewallAllowed = Get-NetFirewallProfile | Where-Object {$_.DefaultInboundAction -eq "Allow"} + +If($FirewallAllowed){$FirewallState += "$($FirewallAllowed.name) Profile is set to $($FirewallAllowed.DefaultInboundAction) inbound traffic"} + +if(!$FirewallState){Write-Host "healthy"} +else { + Write-Host $FirewallState + Write-Diag @($FirewallProfiles,$FirewallAllowed) + exit 1 +} diff --git a/Remove-McAfee.ps1 b/Remove-McAfee.ps1 new file mode 100644 index 0000000..0f8c3a6 --- /dev/null +++ b/Remove-McAfee.ps1 @@ -0,0 +1,4 @@ +# Removes McAfee Apps + +$McAfeeApps = Get-AppxPackage -Name "*McAfee*" -AllUsers | Select-Object * +foreach ($app in $McAfeeApps){Remove-AppxPackage -Package $app.PackageFullName -AllUsers} diff --git a/Run-OrthotracBackup.ps1 b/Run-OrthotracBackup.ps1 new file mode 100644 index 0000000..fbe1287 --- /dev/null +++ b/Run-OrthotracBackup.ps1 @@ -0,0 +1,46 @@ +# Runs an Orthotrac Backup + + function Write-Diag ($messages) { + foreach ($Message in $Messages) { $Message } +} +Function Write-Alert ($message) +{ + write-host "Alert=$message" +} + +Function Get-OMSDir +{ + $Disks = (get-volume).driveletter | Where-Object {$_ -ne $null} + + $OMSDisk = ForEach ($Disk in $Disks) + { + $Drive = "$Disk"+":\" + $Search = Get-ChildItem "$Drive" | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match "Orthotrac"} + if ($Search -ne $null){echo $Disk} + } + + $OMSDir = "$OMSDisk"+":\Orthotrac\OMS" + echo $OMSDir +} + +Function Execute-OrthoBackup +{ + $OMSDir = Get-OMSDir + cd $OMSDir + .\orthobac.exe +} + +Try +{ + Execute-OrthoBackup + Write-Alert "Orthotrac Backup Ran Correctly" + Write-Diag @("Orthotrac Backup Ran Correctly" | out-string) + exit 0 +} +Catch +{ + Write-Alert "Orthotrac Backup did NOT run Correctly" + Write-Diag @("Orthotrac Backup did NOT run Correctly" | out-string) + exit 1 +} +exit 1