Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module $env:SyncroModule -WarningAction SilentlyContinue
- $Date = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
- Write-Host This script ran on $Date
- Add-Content c:\SPI\ScriptHistory.txt "Daily Server Maintenance Script Ran on $Date"
- ################################################################################################################################
- ################################################################################################################################
- #Check if server or workstation
- $OSType = (Get-ComputerInfo).OsProductType
- if ($OSType -eq 'Workstation') {
- Write-Host System is a $OSType. Verify script should be running here.
- Rmm-Alert -Category "Incorrect Script" -Body "Verify script should be running here."
- exit 1
- }
- #Notify us what OS Type it is
- Write-Host System is a $OSType
- ################################################################################################################################
- ################################################################################################################################
- #Purpose: Maintenance script to keep pc's running fresh
- #This script performs the following:
- #Show Uptime Hours and Days
- #Pull CPU Temp
- #Check Dell RAID Virtual Disks
- #Check Dell RAID Physical Disks
- ################################################################################################################################
- ################################################################################################################################
- #Show Uptime Hours and Days
- $os=Get-WmiObject win32_operatingsystem
- $UptimeHours = ((get-date) - ($os.ConvertToDateTime($os.lastbootuptime))).Hours
- Write-Host "System Uptime is: $UptimeHours Hour(s)"
- Set-Asset-Field -Subdomain "surepointit" -Name "System Uptime Hours" -Value $UptimeHours
- $MaxDaysUptime = "30"
- $Boot = Get-WmiObject Win32_OperatingSystem
- $LastRebootTime = $Boot.ConvertToDateTime($Boot.LastBootUpTime)
- $Today = Get-Date
- $DiffDays = $Today.Date - $LastRebootTime
- $UptimeDays = "$($DiffDays.Days) days since last reboot"
- $UptimeDays
- Write-Host "Days since boot: $($DiffDays.TotalDays)"
- Set-Asset-Field -Subdomain "surepointit" -Name "System Uptime Days" -Value $DiffDays.Days
- if($DiffDays.TotalDays -gt $MaxDaysUptime) {
- Rmm-Alert -Category "Monitor - Uptime" -Body "$UptimeDays"
- exit
- }
- Close-Rmm-Alert -Category "Monitor - Uptime"
- ################################################################################################################################
- ################################################################################################################################
- #Pull CPU Temp
- #Notify if this is a vm
- $Computer = Get-CimInstance -ClassName 'Win32_ComputerSystem'
- if ($Computer.Model -like 'Virtual*') {
- Write-Host "Server is a VM"
- Set-Asset-Field -Name "CPU Temp" -Value "VM"
- }
- else {
- Write-Host "Server is not a VM, continuing."
- }
- $warningTemp = 180
- $alarmTemp = 185
- $probeInstalled = Test-Path -Path "C:\temp\temp-probe"
- If ($probeInstalled){
- Write-Host "Installed - running the probe"
- Start-Process -FilePath "C:\temp\temp-probe\TempProber.exe" -NoNewWindow -Wait -RedirectStandardOutput C:\temp\temp-probe\temperature.txt -RedirectStandardError C:\temp\temp-probe\temperature_error.txt
- } ELSE {
- Write-Host "Unzipping first.."
- Expand-Archive C:\temp\temp-probe.zip -DestinationPath C:\temp\temp-probe
- Write-Host "running the probe"
- Start-Process -FilePath "C:\temp\temp-probe\TempProber.exe" -NoNewWindow -Wait -RedirectStandardOutput C:\temp\temp-probe\temperature.txt -RedirectStandardError C:\temp\temp-probe\temperature_error.txt
- }
- $result = gc C:\temp\temp-probe\temperature.txt
- $cpuLine = $result -match "CPU"
- IF ($cpuLine) {
- $temperature = $cpuline | select-string -pattern '\d+' -allmatches | % { $_.Matches } | % { $_.Value }
- Set-Asset-Field -Name "CPU Temp" -Value $temperature
- IF ([int]$temperature -gt $alarmTemp){
- write-host "Host is HOT!"
- Rmm-Alert -Category 'cpu_temp_alarm' -Body "CPU is over Alarm Temp with a value of $temperature. The Alarm temp is set to $alarmTemp"
- exit
- }
- ELSEIF ([int]$temperature -gt $warningTemp){
- write-host "Host is warming up..."
- }
- ELSE {
- write-host "Just chilling at $temperature currently..."
- Close-Rmm-Alert -Category "'cpu_temp_alarm'"
- }
- } ELSE {
- write-host "Could not find a CPU result from openhardwaremonitor"
- }
- #Clean up our temp file on the way out!
- Remove-Item "C:\temp\temp-probe\temperature.txt"
- ################################################################################################################################
- ################################################################################################################################
- #Check Dell RAID Virtual Disks
- # Check to see if this server is a physical host
- if ((Get-WmiObject -Namespace "root\cimv2" -Class Win32_ComputerSystem).Model -like '*Virtual*') {
- Write-Host "Unsupported Server. This can only run on a physical host."
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- # Check to see if this server is a Dell.
- if ((Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer -notlike 'Dell*') {
- Write-Host "System Manufacturer is not Dell, exiting..."
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- # Check to see if this server is a PowerEdge.
- if ((Get-CimInstance -ClassName Win32_ComputerSystem).Model -notlike 'PowerEdge*') {
- Write-Host "System Manufacturer is not a PowerEdge, exiting..."
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- $version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").CurrentVersion
- if ($Version -lt "6.3") {
- Write-Host "Unsupported OS. This component requires at least Server 2012R2"
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- try {
- omconfig preferences cdvformat delimiter=comma
- $OmReport = omreport storage vdisk -fmt cdv | select-string -SimpleMatch "ID,Status," -Context 0, 5000
- }
- catch {
- throw "Error: omreport Command has Failed: $($_.Exception.Message). Check if Dell OpenManage is installed and OMReport is in the PATH variable."
- }
- $VDarray = convertfrom-csv $OmReport -Delimiter ","
- foreach ($VirtualDisk in $VDarray | where-object { $_.'> ID' -in 0..1000 }) {
- if ($($virtualdisk.State) -eq "Ready" -or $($virtualdisk.Status) -eq "Ok") {
- }
- else {
- write-host "$($VirtualDisk.Name) / $($VirtualDisk.'Device Name') Has Status $($VirtualDisk.Status) / $($VirtualDisk.State)"
- $RAIDStatus = "failed"
- }
- }
- if ($RAIDStatus) {
- Rmm-Alert -Category 'RAID' -Body 'Potential RAID failure. Please investigate'
- if($CreateTicket -eq "Yes"){
- Create-Syncro-Ticket -Subject "Potential RAID failure" -IssueType "RAID" -Status "New"
- }
- }
- ################################################################################################################################
- ################################################################################################################################
- #Check Dell RAID Physical Disk
- # Check to see if this server is a physical host
- if ((Get-WmiObject -Namespace "root\cimv2" -Class Win32_ComputerSystem).Model -like '*Virtual*') {
- Write-Host "Unsupported Server. This can only run on a physical host."
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- # Check to see if this server is a Dell.
- if ((Get-CimInstance -ClassName Win32_ComputerSystem).Manufacturer -notlike 'Dell*') {
- Write-Host "System Manufacturer is not Dell, exiting..."
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- # Check to see if this server is a PowerEdge.
- if ((Get-CimInstance -ClassName Win32_ComputerSystem).Model -notlike 'PowerEdge*') {
- Write-Host "System Manufacturer is not a PowerEdge, exiting..."
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- exit 0
- }
- $version = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").CurrentVersion
- if ($Version -lt "6.3") {
- Throw "Unsupported OS. This component requires at least Server 2012R2"
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- Write-Host Script completed on $Date
- }
- try {
- omconfig preferences cdvformat delimiter=pipe
- [xml]$ControllerList = (omreport storage controller -fmt xml)
- $OmReport = foreach ($Controller in $ControllerList.oma.controllers.DCStorageObject.GlobalNo.'#text') {
- omreport storage pdisk controller=$Controller -fmt cdv | select-string -SimpleMatch "ID|Status" -Context 0, 5000
- }
- }
- catch {
- throw "Error: omreport Command has Failed: $($_.Exception.Message). Check if Dell OpenManage is installed and OMReport is in the PATH variable."
- }
- $Parray = convertfrom-csv $OmReport -Delimiter '|'
- $StatusList = @("Online", "OK", "Ready")
- $PDResults = foreach ($PhysicalDisk in $Parray | where-object { $_.status -ne 'Status' }) {
- [PSCustomObject]@{
- DiskName = $PhysicalDisk.name
- SerialNumber = $($PhysicalDisk.'Serial No.')
- Status = $($PhysicalDisk.Status)
- State = $($PhysicalDisk.State)
- 'Part Number' = $($physicaldisk.'Part Number')
- 'Failure Predicted' = $PhysicalDisk.'Failure Predicted'
- }
- }
- $PDResultsFiltered = $PDResults | Where-Object { $_.state -notin $StatusList -or $_.status -notin $StatusList -or $_.'Failure Predicted' -ne 'No' }
- if (!$PDResultsFiltered) {
- write-host "Healthy"
- }
- else {
- Rmm-Alert -Category 'Disks' -Body 'Potential physical disk failure. Please investigate'
- if($CreateTicket -eq "Yes"){
- Create-Syncro-Ticket -Subject "Potential disk failure" -IssueType "Disk" -Status "New"
- }
- }
- ################################################################################################################################
- ################################################################################################################################
- Set-Asset-Field -Name "Daily Last Ran" -Value $Date
- Log-Activity -Message "Daily Maintenance Script Ran" -EventName "Maintenance Script"
- $CompletionDate = Get-Date -Format "MM/dd/yyyy HH:mm:ss"
- Write-Host Script completed on $CompletionDate
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement