Intune Initial Scripts Backup
This commit is contained in:
70
dump/WSUS_Scripts/Backups/new-Patch-WSUSGroup.ps1
Normal file
70
dump/WSUS_Scripts/Backups/new-Patch-WSUSGroup.ps1
Normal file
@@ -0,0 +1,70 @@
|
||||
<#
|
||||
|
||||
$ErrorActionPreference = "Ignore"
|
||||
$WSUSGroup = Read-Host "Enter Target Group Name"
|
||||
$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
|
||||
Foreach ($server in $servers) {Install-WindowsUpdate -ComputerName $server -AsJob}
|
||||
|
||||
#Function Restart {# Force Reboot of Group (when auto failed) un-rem and run line below.
|
||||
#Foreach ($server in $servers) {Restart-Computer -ComputerName $server -Force}}
|
||||
|
||||
#Write-Host "Type Restart and press enter to reboot the $WSUSGroup WSUS Computer Group"
|
||||
Read-Host -Prompt "Press Enter to exit"
|
||||
#>
|
||||
|
||||
#################################################################################################################################
|
||||
#$ErrorActionPreference = "Ignore"
|
||||
$WSUSGroup = Read-Host "Enter Target Group Name"
|
||||
|
||||
$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
|
||||
|
||||
#$servers = "W2012A","W2012B","slfkjsdl"
|
||||
#$WSUSGroup = "Test GGroupppppp"
|
||||
|
||||
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
|
||||
$Dte = Get-Date -UFormat %m-%d-%Y
|
||||
$Collect_Jobs = @()
|
||||
$Patch_Job = @()
|
||||
|
||||
$servers | Out-File $Location\Patching-Day\"$WSUSGroup"-Server-Patching-Today-$Dte.txt
|
||||
$servers | Out-File E:\WSUS_Scripts\Patching-Day\"$WSUSGroup"-Server-Patching-Today-Backup-$Dte.txt
|
||||
|
||||
Foreach ($server in $servers) {
|
||||
|
||||
New-EventLog -LogName Application -Source "Patching-Started" -ErrorAction SilentlyContinue -ComputerName $server
|
||||
New-EventLog -LogName Application -Source "Patching-Finished" -ErrorAction SilentlyContinue -ComputerName $server
|
||||
New-EventLog -LogName System -Source "Reboot-After-Patching" -ErrorAction SilentlyContinue -ComputerName $server
|
||||
Write-EventLog -LogName Application -Source "Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell - Remote" -ComputerName $server -ErrorAction SilentlyContinue
|
||||
|
||||
$Patch_Job += Start-Job -ScriptBlock { Param($server) Install-WindowsUpdate -ComputerName $server } -Name "$server-Patching" -ArgumentList $server
|
||||
|
||||
Invoke-Command $server -ErrorAction SilentlyContinue {
|
||||
New-EventLog -LogName Application -Source "Patching-Started" -ErrorAction SilentlyContinue
|
||||
New-EventLog -LogName Application -Source "Patching-Finished" -ErrorAction SilentlyContinue
|
||||
New-EventLog -LogName System -Source "Reboot-After-Patching" -ErrorAction SilentlyContinue
|
||||
Write-EventLog -LogName Application -Source "Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell - Invoke"
|
||||
}#endInvoke
|
||||
|
||||
Install-WindowsUpdate -ComputerName $server -AsJob
|
||||
|
||||
}#endForeach
|
||||
|
||||
Get-Job
|
||||
|
||||
$Patch_Job | Export-Csv $Location\Patching-Day\Patching-Jobs-$Dte.csv -NoTypeInformation
|
||||
$Patch_Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Jobs-Backup-$Dte.csv -NoTypeInformation
|
||||
|
||||
$Collect_Jobs = Get-Job | Export-Csv $Location\Patching-Day\Collect-Patching-Jobs-$Dte.csv -NoTypeInformation
|
||||
$Collect_Jobs = Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Collect-Patching-Jobs-Backup-$Dte.csv -NoTypeInformation
|
||||
|
||||
$Patch_Job | Select @{n="Server";e={$_.Name.Split('-')[0]}},@{n="MainJobID";e={$_.ID}},@{n="MainJobName";e={$_.Name}},@{n="ChildJobID";e={$_.Childjobs.ID}},@{n="ChildJobState";e={$_.Childjobs.State}},PSBeginTime,PSEndTime,Command | Export-Csv $Location\Patching-Day\Jobs-ChildJobs-$Dte.csv -NoTypeInformation
|
||||
$Patch_Job | Select @{n="Server";e={$_.Name.Split('-')[0]}},@{n="MainJobID";e={$_.ID}},@{n="MainJobName";e={$_.Name}},@{n="ChildJobID";e={$_.Childjobs.ID}},@{n="ChildJobState";e={$_.Childjobs.State}},PSBeginTime,PSEndTime,Command | Export-Csv E:\WSUS_Scripts\Patching-Day\Jobs-ChildJobs-Backup-$Dte.csv -NoTypeInformation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
29
dump/WSUS_Scripts/Backups/new-Reboot-WSUSGroup-backup1.ps1
Normal file
29
dump/WSUS_Scripts/Backups/new-Reboot-WSUSGroup-backup1.ps1
Normal file
@@ -0,0 +1,29 @@
|
||||
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
|
||||
$Dte = Get-Date -UFormat %m-%d-%Y
|
||||
|
||||
$WSUSGroup = Read-Host "Enter Target Group Name"
|
||||
$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
|
||||
|
||||
$servers | Out-File $Location\Patching-Day\"$WSUSGroup"-Servers-Rebooting-$Dte.txt -ErrorAction SilentlyContinue
|
||||
$servers | Out-File E:\WSUS_Scripts\Patching-Day\"$WSUSGroup"-Servers-Rebooting-Backup-$Dte.txt -ErrorAction SilentlyContinue
|
||||
|
||||
$Patch_Job | Export-Csv $Location\Patching-Day\Patching-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
$Patch_Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
|
||||
Get-Job | Export-Csv $Location\Patching-Day\Patching-Get-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Get-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
|
||||
$Collect_Jobs = Get-Job | Export-Csv $Location\Patching-Day\Patching-Collect-Patching-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation
|
||||
$Collect_Jobs = Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Collect-Patching-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation
|
||||
|
||||
Foreach ($server in $servers) {
|
||||
|
||||
Invoke-Command $server -ErrorAction SilentlyContinue {
|
||||
#New-EventLog -LogName Application -Source "Powershell-WSUS-Patching-Finished" -ErrorAction SilentlyContinue
|
||||
#New-EventLog -LogName System -Source "Powershell-Reboot-After-Patching" -ErrorAction SilentlyContinue
|
||||
Write-EventLog -LogName Application -Source "Patching-Finished" -EntryType Information -EventId 7891 -Message "Powershell-WSUS-Patching-Finished"
|
||||
Write-EventLog -LogName System -Source "Reboot-After-Patching" -EntryType Information -EventId 7892 -Message "Server Rebooting After Patching"
|
||||
}#endInvoke
|
||||
Restart-Computer -ComputerName $server -Force -Verbose
|
||||
|
||||
}#endForeach
|
||||
32
dump/WSUS_Scripts/Backups/new-Reboot-WSUSGroup.ps1
Normal file
32
dump/WSUS_Scripts/Backups/new-Reboot-WSUSGroup.ps1
Normal file
@@ -0,0 +1,32 @@
|
||||
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
|
||||
$Dte = Get-Date -UFormat %m-%d-%Y
|
||||
|
||||
$WSUSGroup = Read-Host "Enter Target Group Name"
|
||||
$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
|
||||
|
||||
$servers | Out-File $Location\Patching-Day\"$WSUSGroup"-Servers-Rebooting-$Dte.txt -ErrorAction SilentlyContinue
|
||||
$servers | Out-File E:\WSUS_Scripts\Patching-Day\"$WSUSGroup"-Servers-Rebooting-Backup-$Dte.txt -ErrorAction SilentlyContinue
|
||||
|
||||
$Patch_Job | Export-Csv $Location\Patching-Day\Patching-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
$Patch_Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
|
||||
Get-Job | Export-Csv $Location\Patching-Day\Patching-Get-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Get-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation -ErrorAction SilentlyContinue
|
||||
|
||||
$Collect_Jobs = Get-Job | Export-Csv $Location\Patching-Day\Patching-Collect-Patching-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation
|
||||
$Collect_Jobs = Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\Patching-Collect-Patching-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation
|
||||
|
||||
Foreach ($server in $servers) {
|
||||
|
||||
Write-EventLog -LogName Application -Source "Patching-Finished" -EntryType Information -EventId 7891 -Message "Powershell-WSUS-Patching-Finished - Remote" -ComputerName $server -ErrorAction SilentlyContinue
|
||||
Write-EventLog -LogName System -Source "Reboot-After-Patching" -EntryType Information -EventId 7892 -Message "Server Rebooting After Patching - Remote" -ComputerName $server -ErrorAction SilentlyContinue
|
||||
|
||||
Invoke-Command $server -ErrorAction SilentlyContinue {
|
||||
#New-EventLog -LogName Application -Source "Powershell-WSUS-Patching-Finished" -ErrorAction SilentlyContinue
|
||||
#New-EventLog -LogName System -Source "Powershell-Reboot-After-Patching" -ErrorAction SilentlyContinue
|
||||
Write-EventLog -LogName Application -Source "Patching-Finished" -EntryType Information -EventId 7891 -Message "Powershell-WSUS-Patching-Finished - Invoke" -ErrorAction SilentlyContinue
|
||||
Write-EventLog -LogName System -Source "Reboot-After-Patching" -EntryType Information -EventId 7892 -Message "Server Rebooting After Patching - Invoke" -ErrorAction SilentlyContinue
|
||||
}#endInvoke
|
||||
Restart-Computer -ComputerName $server -Force -Verbose
|
||||
|
||||
}#endForeach
|
||||
15
dump/WSUS_Scripts/Backups/new-WSUS-PendingReboot.ps1
Normal file
15
dump/WSUS_Scripts/Backups/new-WSUS-PendingReboot.ps1
Normal file
@@ -0,0 +1,15 @@
|
||||
#import correct file
|
||||
#Uncomment Restart-Computer
|
||||
|
||||
$Server_Reboot_Before_Patching = Import-Csv E:\WSUS_Scripts\Files\PENDING-Reboots-10-08-2019.csv | ? { $_.RebootPending -eq "True" } | select computer
|
||||
|
||||
$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
|
||||
Restart-Computer $_ -Force -Verbose
|
||||
}#end%
|
||||
|
||||
|
||||
Reference in New Issue
Block a user