Files
Intune/dump/WSUS_Scripts/0-new-WSUS-PendingReboot.ps1

48 lines
2.8 KiB
PowerShell

#import correct file
#Uncomment Restart-Computer
$Dte = Get-Date -UFormat %m-%d-%Y
#########################################################################################
#$WSUSGroup = gc H:\Scripts\Patching\_Group-Config-File\Config-WSUS-Group.txt
$WSUSGroup = "Tier0"
$Current_Month = (Get-Date -UFormat %B)
$Current_Year = (Get-Date -UFormat %Y)
#$WSUSGroup = Read-Host "Enter Target Group Name"
$Folder = "E:\WSUS_Scripts\Patching-Day\$Current_Month-$Current_Year"
$Group_Folder = "$Folder\$WSUSGroup-$Current_Month-PENDING-Reboot"
$Pending_Reboot_File_Name = "$Group_Folder\$WSUSGroup-PENDING-Reboots-$Current_Month"
#If(!(Test-Path E:\WSUS_Scripts\Patching-Day\$Current_Month-$Current_Year\$WSUSGroup-$Current_Month-Patching)) { New-Item -Path "E:\WSUS_Scripts\Patching-Day" -ItemType Directory -Name $WSUSGroup-$Current_Month-Patching }
#########################################################################################
#$Server_Reboot_Before_Patching = Import-Csv "E:\WSUS_Scripts\Patching-Day\$Current_Month-$Current_Year\$Group_Folder\$Pending_Reboot_File_Name.csv" | ? { $_.RebootPending -eq "True" } | select computer
#$Server_Reboot_Before_Patching | Export-Csv "E:\WSUS_Scripts\Patching-Day\$Current_Month-$Current_Year\$Group_Folder\$WSUSGroup-Servers-Rebooting-Before-Patching-$Dte.csv" -NoTypeInformation
$Server_Reboot_Before_Patching = Import-Csv "$Pending_Reboot_File_Name.csv" | ? { $_.RebootPending -eq "True" } | select computer
Write-Host "$WSUSGroup - Server Count: $($Server_Reboot_Before_Patching.count)" -ForegroundColor Yellow
$Server_Reboot_Before_Patching.Computer | % {
#Write-EventLog -LogName System -Source "Powershell-WSUS-Reboot-Before-Patching" -EntryType Information -EventId 7893 -Message "Reboot-Before-Patching-Remote" -ErrorAction SilentlyContinue
#Invoke-Command $_ -ErrorAction SilentlyContinue {
# New-EventLog -LogName System -Source "Reboot-Before-Patching" -ErrorAction SilentlyContinue
# Write-EventLog -LogName System -Source "Reboot-Before-Patching" -EntryType Information -EventId 7893 -Message "Reboot-Before-Patching-Invoke" -ErrorAction SilentlyContinue
#}#endInvoke
Write-Host "Rebooting --- $_"
xRestart-Computer $_ -Force -Verbose
}#end%
##############################################################################################################################
<#
$Server_Reboot_Before_Patching.computer | % { $T = Test-Connection -ComputerName $_ -Count 1 -ErrorAction SilentlyContinue
If($T) { Write-Host "Server $_ -- Responding" -ForegroundColor Green } Else { Write-Host "Server $_ -- Not Responding" -ForegroundColor Red }
}
$Server_Reboot_Before_Patching.computer | % { gwmi win32_operatingsystem -ComputerName $_ | select @{n="Server";e={$_.PSComputername}},@{n="LastBootup";e={$_.Converttodatetime($_.LastBootUpTime)}}}
#>