Intune Initial Scripts Backup

This commit is contained in:
2025-04-21 14:21:38 -04:00
commit 71764cd10f
241 changed files with 28218 additions and 0 deletions

View File

@@ -0,0 +1,67 @@

$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
#################################################################################################################################
$Dte = Get-Date -UFormat %m-%d-%Y
$Current_Month = (Get-Date -UFormat %B)
#$WSUSGroup = gc H:\Scripts\Patching\_Group-Config-File\Config-WSUS-Group.txt
#$Group_Folder = "$WSUSGroup-$Current_Month-Patching"
#$Group = "NCRA - Development Servers"
#################################################################################################################################
$servers = ""
$WSUSGroup = Read-Host "Enter Target Group Name"
#$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
$Group_Folder = "$WSUSGroup-$Current_Month-Patching"
#$servers = Import-Csv E:\WSUS_Scripts\Patching-Day\December-2019\$Group_Folder\CCXQ1-November-Prep-Files\$WSUSGroup-Target-Group-Computers-$Current_Month.csv | select -ExpandProperty FullDomainName
$servers = Import-Csv E:\WSUS_Scripts\Patching-Day\December-2019\$WSUSGroup.csv | select -ExpandProperty "Server Name"
#$servers | Out-File $Location\Patching-Day\$Group_Folder\$WSUSGroup-Servers-Rebooting-$Dte.txt -ErrorAction SilentlyContinue
$servers | Out-File E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Servers-Rebooting-Backup-$Dte.txt -ErrorAction SilentlyContinue
#$servers = $servers | ? { $_ -ne "qadf001.ccx.carecentrix.com"}
#$Patch_Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation -ErrorAction SilentlyContinue
$Patch_Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation -ErrorAction SilentlyContinue
Get-Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Get-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation -ErrorAction SilentlyContinue
Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Get-Jobs-$Dte-Before-Reboot-Backup.csv -NoTypeInformation -ErrorAction SilentlyContinue
#$Collect_Jobs = Get-Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Collect-Patching-Jobs-$Dte-Before-Reboot.csv -NoTypeInformation
$Collect_Jobs = Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-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
<#
$servers | % { $T = Test-Connection -ComputerName $_ -Count 1 -ErrorAction SilentlyContinue
If($T) { Write-Host "Server $_ -- Responding" -ForegroundColor Green } Else { Write-Host "Server $_ -- Not Responding" -ForegroundColor Red }
}
#>
# $Servers | % { Get-EventLog -LogName System -ComputerName $_.computer | ? { $_.EventID -eq '7893' } }
# $Servers | % { gwmi win32_operatingsystem -ComputerName $_ | select @{n="Server";e={$_.PSComputername}},@{n="LastBootup";e={$_.Converttodatetime($_.LastBootUpTime)}}}