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,26 @@
$WSUSGroup = Read-Host "Enter Target Group Name"
$Computers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
foreach ($computer in $computers){
if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else {$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="Computer"; Expression={$Computer}}, Date,
@{name="Operation"; expression={switch($_.operation){
1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}},
@{name="Status"; expression={switch($_.resultcode){
1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"};
4 {"Failed"}; 5 {"Aborted"}
}}},Title| Where {$_.Status -eq "Failed"}|Write-Host|Export-Csv -NoType "$Env:userprofile\Desktop\$wsusgroup-Failed-WindowsUpdates.csv" -Append}}

View File

@@ -0,0 +1,26 @@
$WSUSGroup = Read-Host "Enter Target Group Name"
$Computers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
foreach ($computer in $computers){
if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else {$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="Computer"; Expression={$Computer}}, Date,
@{name="Operation"; expression={switch($_.operation){
1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}},
@{name="Status"; expression={switch($_.resultcode){
1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"};
4 {"Failed"}; 5 {"Aborted"}
}}},Title| Where {$_.Status -eq "In Progress"}|Write-Host}}

View File

@@ -0,0 +1,26 @@
$WSUSGroup = Read-Host "Enter Target Group Name"
$Computers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
foreach ($computer in $computers){
if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else {$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="Computer"; Expression={$Computer}}, Date,
@{name="Operation"; expression={switch($_.operation){
1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}},
@{name="Status"; expression={switch($_.resultcode){
1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"};
4 {"Failed"}; 5 {"Aborted"}
}}},Title| Where {$_.Status -eq "In Progress"}|Write-Host}}

View File

@@ -0,0 +1,28 @@
#https://gallery.technet.microsoft.com/scriptcenter/Get-Installed-FailedWindows-9f28742a
$WSUSGroup = Read-Host "Enter Target Group Name"
$Computers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
foreach ($computer in $computers){
if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else {$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | Select-Object @{Name="Computer"; Expression={$Computer}}, Date,
@{name="Operation"; expression={switch($_.operation){
1 {"Installation"}; 2 {"Uninstallation"}; 3 {"Other"}}}},
@{name="Status"; expression={switch($_.resultcode){
1 {"In Progress"}; 2 {"Succeeded"}; 3 {"Succeeded With Errors"};
4 {"Failed"}; 5 {"Aborted"}
}}},Title| Where {$_.Status -eq "In Progress"}}}

View File

@@ -0,0 +1,19 @@
Import-Module ActiveDirectory
Import-Module WindowsUpdate
$ServerList = Import-Csv 'C:\Users\abamaso-ccxadmin\Desktop\CompletedProd_WindowsServers - Classifications.csv'
foreach ($Server in $ServerList) {
$patchingtier = $Server.Classification
switch ($patchingtier){
"Tier0 - Infrastructure" {Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server.'Server Name'| Add-WsusComputer -TargetGroupName "Tier0 - Infrastructure"}
"Tier1 - Critical Infrastructure" {Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server.'Server Name'| Add-WsusComputer -TargetGroupName "Tier1 - Critical Infrastructure"}
"Tier2 - File Servers" {Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server.'Server Name'| Add-WsusComputer -TargetGroupName "Tier2 - File Servers"}
"Tier2 - Application Servers" {Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server.'Server Name'| Add-WsusComputer -TargetGroupName "Tier2 - Application Servers"}
}
Write-host $Server.'Server Name'" Sorted into Group"
}

Binary file not shown.

View File

@@ -0,0 +1,603 @@
#
# WSUS_Sorting_HAT.PS1
#
#DOCUMENTATION:
#Written by Kevin Trent, kevin.trent@carecentrix.com
#CHANGE LOG:
#Version 1.0 6/12/2018 - First functional edition - Kevin Trent
#UPGRADES:
# Planned:
# Add auto detection of new OU and auto creation of new function. - KJT
#DESCRIPTION:
#WSUS Server-Side targeting chosen to enable flexibility with group assignment. Sorting Hat, takes the place of client-side targeting in a GPO.
#Servers are still added to the unassigned computers group via linked GPO:
#(Prod Server SUS 2016 - PSUS002 - Server Side Targeting, DEV Server SUS 2016 - PSUS002 - Server Side Targeting, QA Server SUS 2016 - PSUS002 - Server Side Targeting)
#Each function sorts systems from the WSUS unassigned computers group to an appropriate target group based on the AD OU.
#MAINTENANCE:
#NEW Active Directory OUs require reciprocal functions to be added.
#New Function Copy/Paste existing function and make these required changes:
#Function name = WSUS Group Name, remove spaces - between each word.
#Variable name - WSUS Group Name, remove spaces change - to _. TargetGroupName = WSUS Group name.
#Canonicalname = OU with wildcard (*) in place of machine name(s).
#Find Canonicalname of a group by running the following command against a machine in that OU: Get-ADComputer -Identity qbiz111 -Properties *|select CanonicalName
#Add Group function to the Run function: (If $newservers.count -gt 0) Scriptblock near the bottom, so that the new function is called when the script is executed.
#Add comment to the ChangeLog remark above
#Module Import. This Script requires RSAT and PowerShell v3.0 or higher on the executing system.
Import-Module ActiveDirectory
Import-Module WindowsUpdate
#System Collection:
#Building the collections to be sorted from the WSUS unassigned computers group removes the need to validate each member.
#Each array memeber can only be in the collection if it passed cetificate, protocol, and connectivity requirements.
$newserversfull = Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -ComputerTargetGroups "Unassigned Computers"|select Fulldomainname -ExpandProperty Fulldomainname
#Shortening the array member names to a useable Get-ADComputer Identity
$newservers = Foreach ($server in $newserversfull) {$server.split(.)[0]}
#SORTING FUNCTIONS:
#Each function runs each memeber of the collection through a loop that contains an AD-OU query. If the member(s) are in the specified AD-OU they are inserted into the WSUS Target Group.
#For simplified locating; functions are grouped under comments with the WSUS group parent name. Example, NCRA QUALITY ASSURANCE SERVERS or CTHA PRODUCTION SERVERS
#CTHA PRODUCTION SERVERS
Function CTHA-Verint-PROD {
$CTHA_Verint_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/CTHA/Servers/Production Servers/Verint Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $CTHA_Verint_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "CTHA - Verint - PROD"
}
}
#KSOP PRODUCTION SERVERS
Function KSOP-Verint-PROD {
$KSOP_Verint_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/KSOP/Servers/Production Servers/Verint Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $KSOP_Verint_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "KSOP - Verint - PROD"
}
}
#AZPH PRODUCTION SERVERS
Function AZPH-Verint-PROD {
$AZPH_Verint_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/AZPH/Servers/Production Servers/Verint Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $AZPH_Verint_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "AZPH - Verint - PROD"
}
}
#FLT2 PRODUCTION SERVERS
Function FLT2-Application-PROD {
$FLT2_Application_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/FLT2/Servers/Production Servers/Application Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $FLT2_Application_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "FLT2 - Application - PROD"
}
}
Function FLT2-Verint-PROD {
$FLT2_Verint_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/FLT2/Servers/Production Servers/Verint Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $FLT2_Verint_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "FLT2 - Verint - PROD"
}
}
Function FLT2-Voice-PROD {
$FLT2_Voice_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/FLT2/Servers/Production Servers/Voice Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $FLT2_Voice_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "FLT2 - Voice - PROD"
}
}
#NCRA DEVELOPMENT SERVERS
Function NCRA-Application-DEV {
$NCRA_Application_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/Application Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Application_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Application - DEV"
}
}
Function NCRA-BizTalk-DEV {
$NCRA_BizTalk_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/BizTalk Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_BizTalk_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - BizTalk - DEV"
}
}
Function NCRA-Edifecs-DEV {
$NCRA_Edifecs_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/Edifecs Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Edifecs_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Edifecs - DEV"
}
}
Function NCRA-Remote-Desktop-DEV{
$NCRA_Remote_Desktop_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/Remote Desktop Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Remote_Desktop_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Remote Desktop - DEV"
}
}
Function NCRA-SQL-DEV {
$NCRA_SQL_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/SQL Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_SQL_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - SQL - DEV"
}
}
Function NCRA-Terminal-Servers-DEV {
$NCRA_Terminal_Servers_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/Terminal Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Application_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Terminal Servers - DEV"
}
}
Function NCRA-Voice-DEV {
$NCRA_Voice_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/Voice Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Voice_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Voice - DEV"
}
}
Function NCRA-Web-DEV {
$NCRA_Web_DEV = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Development Servers/Web Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Web_DEV) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Web - DEV"
}
}
#NCRA PRODUCTION SERVERS:
Function NCRA-Application-PROD {
$NCRA_Application_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Application Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Application_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Application - PROD"
}
}
Function NCRA-BizTalk-PROD {
$NCRA_BizTalk_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/BizTalk Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_BizTalk_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - BizTalk - PROD"
}
}
Function NCRA-Edifecs-PROD {
$NCRA_Edifecs_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Edifecs Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Edifecs_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Edifecs - PROD"
}
}
Function NCRA-Exchange-PROD {
$NCRA_Exchange_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Exchange Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Exchange_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Exchange - PROD"
}
}
Function NCRA-Mail-Terminal-Servers-PROD {
$NCRA_Mail_Terminal_Servers_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Mail Terminal Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Mail_Terminal_Servers_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Mail Terminal Servers - PROD"
}
}
Function NCRA-Remote-Desktop-Prod {
$NCRA_Remote_Desktop_Prod = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Remote Desktop Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Remote_Desktop_Prod) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Remote Desktop - PROD"
}
}
Function NCRA-SQL-PROD {
$NCRA_SQL_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/SQL Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_SQL_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - SQL - PROD"
}
}
Function NCRA-Terminal-Servers-PROD {
$NCRA_Terminal_Servers_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Terminal Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Terminal_Servers_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Terminal Servers - PROD"
}
}
Function NCRA-Tidal-PROD {
$NCRA_Tidal_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Tidal Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Tidal_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Tidal - PROD"
}
}
Function NCRA-Verint-PROD {
$NCRA_Verint_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Verint Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Verint_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Verint - PROD"
}
}
Function NCRA-Vistar-Terminal-Servers-PROD {
$NCRA_Vistar_Terminal_Servers_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Vistar Terminal Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Vistar_Terminal_Servers_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Vistar Terminal Servers - PROD"
}
}
Function NCRA-Voice-PROD {
$NCRA_Voice_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Voice Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Voice_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Voice - PROD"
}
}
Function NCRA-Web-PROD {
$NCRA_Web_PROD = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/Production Servers/Web Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Web_PROD) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Web - PROD"
}
}
#NCRA QUALITY ASSURANCE SERVERS:
Function NCRA-Application-QA {
$NCRA_Application_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Application Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Application_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Application - QA"
}
}
Function NCRA-BizTalk-QA {
$NCRA_BizTalk_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/BizTalk Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_BizTalk_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - BizTalk - QA"
}
}
Function NCRA-Edifecs-QA {
$NCRA_Edifecs_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Edifecs Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Edifecs_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Edifecs - QA"
}
}
Function NCRA-Remote-Desktop-QA {
$NCRA_Remote_Desktop_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Remote Desktop Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Remote_Desktop_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Remote Desktop - QA"
}
}
Function NCRA-SQL-QA {
$NCRA_SQL_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Remote Desktop Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_SQL_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - SQL - QA"
}
}
Function NCRA-Terminal-Servers-QA {
$NCRA_Terminal_Servers_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Remote Desktop Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Terminal_Servers_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Terminal Servers - QA"
}
}
Function NCRA-Tidal-QA {
$NCRA_Tidal_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Tidal Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Tidal_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - Tidal - QA"
}
}
Function NCRA-Web-QA {
$NCRA_Web_QA = Foreach ($server in $newservers) {
Get-ADComputer -Identity $server -Properties * |
Select dnshostname,canonicalname -ExpandProperty canonicalname|
Where canonicalname -Like "ccx.carecentrix.com/NCRA/Servers/QA Servers/Web Servers/*"|
Select dnshostname -ExpandProperty dnshostname
}
Foreach ($server in $NCRA_Web_QA) {
Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server|Add-WsusComputer -TargetGroupName "NCRA - WEb - QA"
}
}
#RUN:
# This function executes the script if there are new/unsorted servers in the Unassigned Computers group on the WSUS server
Function Run {
If ($newservers.Count -gt 0)
{
CTHA-Verint-PROD
KSOP-Verint-PROD
AZPH-Verint-PROD
FLT2-Application-PROD
FLT2-Verint-PROD
FLT2-Voice-PROD
NCRA-Application-DEV
NCRA-BizTalk-DEV
NCRA-Edifecs-DEV
NCRA-Remote-Desktop-DEV
NCRA-SQL-DEV
NCRA-Terminal-Servers-DEV
NCRA-Voice-DEV
NCRA-Web-DEV
NCRA-Application-PROD
NCRA-BizTalk-PROD
NCRA-Edifecs-PROD
NCRA-Exchange-PROD
NCRA-Mail-Terminal-Servers-PROD
NCRA-Remote-Desktop-Prod
NCRA-SQL-PROD
NCRA-Terminal-Servers-PROD
NCRA-Tidal-PROD
NCRA-Verint-PROD
NCRA-Vistar-Terminal-Servers-PROD
NCRA-Voice-PROD
NCRA-Web-PROD
NCRA-Application-QA
NCRA-BizTalk-QA
NCRA-Edifecs-QA
NCRA-Remote-Desktop-QA
NCRA-SQL-QA
NCRA-Terminal-Servers-QA
NCRA-Tidal-QA
NCRA-Web-QA
}
Else {Send-MailMessage -SmtpServer smtp.ccx.carecentrix.com -From WSUS-Sorting-Hat@carecentrix.com -To kevin.trent@carecentrix.com -Subject "No new unassigned computers"
-Body "Sorting Hat did not dectect any new servers in the WSUS unassigned computers group. No action was taken."}
}
Run
#REPORTING:
#Still working on this section. Sudo-code below.
#Servers Not Registered with WSUS:
#$wsus = get-wsusserver -name psus002 -portnumber 8530|get-wsuscomputer|select -ExpandProperty Fulldomainname
#$windows = Get-ADComputer -Properties * -Filter {(OperatingSystem -like "*Windows Server*")}|Select DNSHostName -ExpandProperty DNSHostName
#$nonreg = Compare-Object $wsus $windows|ForEach-Object {$_.InputObject}
#Servers still in the Unassigned Group
#$unassed = Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -ComputerTargetGroups "Unassigned Computers"|select Fulldomainname -ExpandProperty Fulldomainname

View File

@@ -0,0 +1,7 @@
#Enable VEEAM Job Scheduler at the end of maintenance
Add-PSSnapin -Name VeeamPSSnapIn
Connect-VBRServer -Server PVEB001
Get-VBRJob | where {$_.JobTargetType -eq "Backup" -and $_.IsScheduleEnabled -eq $true} | Enable-VBRJobSchedule
Disconnect-VBRServer
Send-MailMessage -SmtpServer smtp.ccx.carecentrix.com -To windows-admins@carecentrix.com -From backups@carecentrix.com -Subject "Veeam Backups Started" -Body "The Veeam Backup Jobs have been rescheduled after the infrastructure weekend.Please verify they are running as expected."
Exit

View File

@@ -0,0 +1,6 @@
#Disable VEEAM Job Schedule - Schedule to Run at 7pm on maintenance day
Add-PSSnapin -Name VeeamPSSnapIn
Connect-VBRServer -Server PVEB001
Get-VBRJob | where {$_.JobTargetType -eq "Backup" -and $_.IsScheduleEnabled -eq $true} | Disable-VBRJobSchedule
Disconnect-VBRServer

View File

@@ -0,0 +1,68 @@
<#
$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 GGroupp"
$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-$Dte.txt
Foreach ($server in $servers) {
Invoke-Command $server -ErrorAction SilentlyContinue {
New-EventLog -LogName Application -Source "Powershell-WSUS-Patching-Started" -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 "Powershell-WSUS-Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell"
}#endInvoke
#Install-WindowsUpdate -ComputerName $server -AsJob
$Patch_Job += Start-Job -ScriptBlock { Param($server) Install-WindowsUpdate -ComputerName $server } -Name "$server-Patching" -ArgumentList $server
}#endForeach
$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
#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"
$servers | % { Get-EventLog -LogName Application -ComputerName $_ -ErrorAction SilentlyContinue | ? { $_.EventID -eq '7890' -and $_.TimeWritten -like "*$Dte*" } }
#Collect event log

View File

@@ -0,0 +1,35 @@
Import-Module ActiveDirectory
Import-Module WindowsUpdate
$ServerList = Import-Csv 'C:\Users\abamaso-ccxadmin\Desktop\CompletedProd_WindowsServers - Classifications.csv'
$AllServers = @()
foreach ($Server in $ServerList) {
$patchingtier = $Server.Classification
$ServerObject = New-Object psobject
$ComputerValidation = $null
$WSUSComputerObject = Get-WsusServer -Name psus002 -PortNumber 8530|Get-WsusComputer -NameIncludes $server.'Server Name'
$ComputerValidation = $wsuscomputerobject.FullDomainName
$ServerObject | Add-Member -MemberType NoteProperty -Name "Server Name" -Value $server.'Server Name'
$ServerObject | Add-Member -MemberType NoteProperty -Name "Operating System" -Value $server.'Operating System'
$ServerObject | Add-Member -MemberType NoteProperty -Name "Application" -Value $server.Application
if ($ComputerValidation -eq $null) {
$ServerObject | Add-Member -MemberType NoteProperty -Name "WSUS Status" -Value "Server is not in WSUS"
}
else {
$ServerObject | Add-Member -MemberType NoteProperty -Name "WSUS Status" -Value "Server is in WSUS"
}
$AllServers +=$ServerObject
Write-host $Server.'Server Name'" checked in WSUS"
}
$AllServers | export-csv C:\Users\abamaso-ccxadmin\Desktop\WSUSComputers.csv

View File

@@ -0,0 +1,110 @@
<#
$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"
#$servers = "W2012A","W2012B","slfkjsdl"
#$WSUSGroup = "Test GGroupppppp"
#################################################################################################################################
If(Test-Path E:\WSUS_Scripts\Lock_Script.txt) {
Write-Host "The Script is locked for protection. If you are not running it by mistake - Delete the file (E:\WSUS_Scripts\Lock_Script.txt) and run the Script again" -ForegroundColor Yellow
Break
}
Else { New-Item -Path E:\WSUS_Scripts -Name Lock_Script.txt -ItemType File }
#################################################################################################################################
Get-Job | Remove-Job
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
############################################################
#$WSUSGroup = gc H:\Scripts\Patching\_Group-Config-File\Config-WSUS-Group.txt
$Current_Month = (Get-Date -UFormat %B)
############################################################
$Dte = Get-Date -UFormat %m-%d-%Y
$Collect_Jobs = @()
$Patch_Job = @()
$Failed_Jobs = @()
$Receive_Jobs = @()
If(!(Test-Path E:\WSUS_Scripts\Patching-Day\$WSUSGroup-$Current_Month-Patching)) { New-Item -Path "E:\WSUS_Scripts\Patching-Day" -ItemType Directory -Name $WSUSGroup-$Current_Month-Patching }
$servers = ""
$WSUSGroup = Read-Host "Enter Target Group Name"
#$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select -ExpandProperty Fulldomainname
$Group_Folder = "$WSUSGroup-$Current_Month-Patching"
$Servers_Reboot_Only = Import-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\CCXQ1-November-Prep-Files\Manual-$WSUSGroup-OperatingSystems-$Current_Month.csv
$servers = Import-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\CCXQ1-November-Prep-Files\$WSUSGroup-Target-Group-Computers-$Current_Month.csv | select -ExpandProperty FullDomainName
$servers = $servers | ? { $_ -notin $Servers_Reboot_Only.FullDomainName }
#$Failed_Ping_Test = gc $Location\Files\$WSUSGroup-Ping-Failed-$Current_Month.txt
#$servers = $servers | ? { $_ -notin $Failed_Ping_Test }
$servers | Out-File $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Today-$Dte.txt
$servers | Out-File E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Today-Backup-$Dte.txt
Foreach ($server in $servers) {
New-EventLog -LogName Application -Source "Patching-Started" -ErrorAction SilentlyContinue -ComputerName $server -verbose
New-EventLog -LogName Application -Source "Patching-Finished" -ErrorAction SilentlyContinue -ComputerName $server -verbose
New-EventLog -LogName System -Source "Reboot-After-Patching" -ErrorAction SilentlyContinue -ComputerName $server -verbose
Write-EventLog -LogName Application -Source "Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell - Remote" -ComputerName $server -ErrorAction SilentlyContinue -verbose
$Patch_Job += Start-Job -ScriptBlock { Param($server) WindowsUpdate\Install-WindowsUpdate -ComputerName $server } -Name "$WSUSGroup-$server-Patching" -ArgumentList $server
Invoke-Command $server -ErrorAction SilentlyContinue {
New-EventLog -LogName Application -Source "Patching-Started" -ErrorAction SilentlyContinue -verbose
New-EventLog -LogName Application -Source "Patching-Finished" -ErrorAction SilentlyContinue -verbose
New-EventLog -LogName System -Source "Reboot-After-Patching" -ErrorAction SilentlyContinue -verbose
Write-EventLog -LogName Application -Source "Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell - Invoke" -verbose
}#endInvoke
}#endForeach
#Get-Job
$Patch_Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Jobs-$Dte.csv -NoTypeInformation
$Patch_Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Jobs-Backup-$Dte.csv -NoTypeInformation
$Collect_Jobs = Get-Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Collect-Patching-Jobs-$Dte.csv -NoTypeInformation
$Collect_Jobs = Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-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\$Group_Folder\$WSUSGroup-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\$Group_Folder\$WSUSGroup-Jobs-ChildJobs-Backup-$Dte.csv -NoTypeInformation
<#
$Failed_Jobs += $Patch_Job | ? { $_.State -eq "Failed" }
$Failed_Jobs | ft -autosize
$Failed_Jobs | Export-Csv "E:\WSUS_Scripts\Patching-Day\NCRA - Quality Assurance Servers-November-Patching\failed-jobs.csv" -NoTypeInformation
#>
### Running Count
## ( $Patch_Job | ? { $_.State -eq "Running" } ).count
## ( $Patch_Job | ? { $_.State -eq "Completed" } ).count
## ( $Patch_Job | ? { $_.State -eq "Failed" } ).count

View File

@@ -0,0 +1,110 @@
<#
$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"
#$servers = "W2012A","W2012B","slfkjsdl"
#$WSUSGroup = "Test GGroupppppp"
#################################################################################################################################
If(Test-Path E:\WSUS_Scripts\Lock_Script.txt) {
Write-Host "The Script is locked for protection. If you are not running it by mistake - Delete the file (E:\WSUS_Scripts\Lock_Script.txt) and run the Script again" -ForegroundColor Yellow
Break
}
Else { New-Item -Path E:\WSUS_Scripts -Name Lock_Script.txt -ItemType File }
#################################################################################################################################
Get-Job | Remove-Job
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
############################################################
#$WSUSGroup = gc H:\Scripts\Patching\_Group-Config-File\Config-WSUS-Group.txt
$Current_Month = (Get-Date -UFormat %B)
############################################################
$Dte = Get-Date -UFormat %m-%d-%Y
$Collect_Jobs = @()
$Patch_Job = @()
$Failed_Jobs = @()
$Receive_Jobs = @()
If(!(Test-Path E:\WSUS_Scripts\Patching-Day\$WSUSGroup-$Current_Month-Patching)) { New-Item -Path "E:\WSUS_Scripts\Patching-Day" -ItemType Directory -Name $WSUSGroup-$Current_Month-Patching }
$servers = ""
$WSUSGroup = Read-Host "Enter Target Group Name"
#$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select -ExpandProperty Fulldomainname
$Group_Folder = "$WSUSGroup-$Current_Month-Patching"
$Servers_Reboot_Only = Import-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\CCXQ1-November-Prep-Files\Manual-$WSUSGroup-OperatingSystems-$Current_Month.csv
$servers = Import-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\CCXQ1-November-Prep-Files\$WSUSGroup-Target-Group-Computers-$Current_Month.csv | select -ExpandProperty FullDomainName
$servers = $servers | ? { $_ -notin $Servers_Reboot_Only.FullDomainName }
#$Failed_Ping_Test = gc $Location\Files\$WSUSGroup-Ping-Failed-$Current_Month.txt
#$servers = $servers | ? { $_ -notin $Failed_Ping_Test }
$servers | Out-File $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Today-$Dte.txt
$servers | Out-File E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Today-Backup-$Dte.txt
Foreach ($server in $servers) {
New-EventLog -LogName Application -Source "Patching-Started" -ErrorAction SilentlyContinue -ComputerName $server -verbose
New-EventLog -LogName Application -Source "Patching-Finished" -ErrorAction SilentlyContinue -ComputerName $server -verbose
New-EventLog -LogName System -Source "Reboot-After-Patching" -ErrorAction SilentlyContinue -ComputerName $server -verbose
Write-EventLog -LogName Application -Source "Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell - Remote" -ComputerName $server -ErrorAction SilentlyContinue -verbose
$Patch_Job += Start-Job -ScriptBlock { Param($server) WindowsUpdate\Install-WindowsUpdate -ComputerName $server } -Name "$WSUSGroup-$server-Patching" -ArgumentList $server
Invoke-Command $server -ErrorAction SilentlyContinue {
New-EventLog -LogName Application -Source "Patching-Started" -ErrorAction SilentlyContinue -verbose
New-EventLog -LogName Application -Source "Patching-Finished" -ErrorAction SilentlyContinue -verbose
New-EventLog -LogName System -Source "Reboot-After-Patching" -ErrorAction SilentlyContinue -verbose
Write-EventLog -LogName Application -Source "Patching-Started" -EntryType Information -EventId 7890 -Message "Server Patching Started with Powershell - Invoke" -verbose
}#endInvoke
}#endForeach
#Get-Job
$Patch_Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Jobs-$Dte.csv -NoTypeInformation
$Patch_Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-Patching-Jobs-Backup-$Dte.csv -NoTypeInformation
$Collect_Jobs = Get-Job | Export-Csv $Location\Patching-Day\$Group_Folder\$WSUSGroup-Collect-Patching-Jobs-$Dte.csv -NoTypeInformation
$Collect_Jobs = Get-Job | Export-Csv E:\WSUS_Scripts\Patching-Day\$Group_Folder\$WSUSGroup-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\$Group_Folder\$WSUSGroup-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\$Group_Folder\$WSUSGroup-Jobs-ChildJobs-Backup-$Dte.csv -NoTypeInformation
<#
$Failed_Jobs += $Patch_Job | ? { $_.State -eq "Failed" }
$Failed_Jobs | ft -autosize
$Failed_Jobs | Export-Csv "E:\WSUS_Scripts\Patching-Day\NCRA - Quality Assurance Servers-November-Patching\failed-jobs.csv" -NoTypeInformation
#>
### Running Count
## ( $Patch_Job | ? { $_.State -eq "Running" } ).count
## ( $Patch_Job | ? { $_.State -eq "Completed" } ).count
## ( $Patch_Job | ? { $_.State -eq "Failed" } ).count

View 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

View File

@@ -0,0 +1,48 @@
$Location = Split-Path $MyInvocation.MyCommand.Path -Parent
#################################################################################################################################
$Dte = Get-Date -UFormat %m-%d-%Y
$Current_Month = (Get-Date -UFormat %B)
$WSUSGroup = "NCRA - Development Servers"
$Group_Folder = "$WSUSGroup-$Current_Month-Patching"
$Group = "NCRA - Development Servers"
#################################################################################################################################
#$WSUSGroup = Read-Host "Enter Target Group Name"
#$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
$servers = Import-Csv E:\WSUS_Scripts\Files\*$Group*.csv
#$servers = "w2012a","w2012b","testtest"
$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
$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.Computer -ErrorAction SilentlyContinue
Write-EventLog -LogName System -Source "Reboot-After-Patching" -EntryType Information -EventId 7892 -Message "Server Rebooting After Patching - Remote" -ComputerName $server.Computer -ErrorAction SilentlyContinue
Invoke-Command $server.Computer -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.Computer -Force -Verbose
}#endForeach
<#
$servers.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 }
}
#>

View 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

View File

@@ -0,0 +1,10 @@
$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"

View File

@@ -0,0 +1,3 @@
$WSUSGroup = Read-Host "Enter Target Group Name"
$servers = Get-WsusComputer -ComputerTargetGroups "$WSUSGroup" -IncludeSubgroups|select Fulldomainname -ExpandProperty Fulldomainname
Foreach ($server in $servers) {Restart-Computer -ComputerName $server -Force}