-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdatePolicyandRebootGCPS.ps1
114 lines (86 loc) · 2.76 KB
/
UpdatePolicyandRebootGCPS.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<#
.NAME
Update Policy and Reboot GCPS
.SYNOPSIS
Connects to a remote machine, forces a group policy update, then reboots the machine.
.DESCRIPTION
The software for the GCP's is kept upto date through Group Policy, however that can lead to a period of time where different GCPs have different versions.
This script kills the GCP software, then forces a group policy update which will copy the new software over. The GCP is then rebooted which starts the new software.
The script takes in a listing of all the GCP's to be updated. If a GCP is to be skipped, the line needs to have a # in the beginning of the line.
.PARAMETER
.EXAMPLE
Update Policy and Reboot GCPS.ps1
.EXAMPLE
Update Policy and Reboot GCPS.ps1 -UpdateList
#>
[CmdletBinding()]
Param (
[string]$UpdateList
)
#Modules to be imported
#Import-Module ActiveDirectory
#Set flags for debug mode.
If($psBoundParameters['debug'])
{
$DebugPreference = "Continue"
}
Else
{
$DebugPreference = "SilentlyContinue"
}
#Check to see if a list has been given. If is, set the $gcps variable. If not, grab all the computers from AD and set to the $gcps variable.
If($psBoundParameters['UpdateList'])
{
$gcps = Get-Content $UpdateList
}
Else
{
$gcps = dsquery computer "ou=GCP Computers,DC=Security,DC=Local"
For ($i = 0; $i -lt $gcps.Count; $i++)
{
$gcps[$i] = $gcps[$i].Substring(4,$gcps[$i].IndexOf(",")-4)
}
}
$jobs = @()
$ScriptBlock =
{
Param ([string]$computername)
Invoke-Command -computername $computername { Stop-Process -Force -processname "GatePad" }
Invoke-Command -computername $computername { gpupdate /force}
Write-Debug -Message "Working on machine $ComputerName"
Write-Host "Updating on $ComputerName."
Start-Sleep 5
#Invoke-Command -Computername $Computername { shutdown /r /t 0 }
}
Write-Host "Starting the updates on the Gate Control Panels. Once all have been updated they will be rebooted." -ForegroundColor Green
Write-Debug -Message "After starting the gpudate there is a 5 second pause betwen starting updates."
Foreach($gcp in $gcps)
{
if ($gcp.StartsWith("#"))
{
Write-Debug -Message "$gcp skipped..."
}
else
{
Write-Debug -Message "Updating $gcp"
$jobs += Start-Job -ScriptBlock $ScriptBlock -ArgumentList $gcp
}
}
Write-Host "Waiting for jobs to finish"
Write-Debug -Message "There are still jobs running. When there are 0 jobs this will move on."
Wait-Job $jobs.id
Remove-Job -State Completed
Write-Host "Rebooting units"
Foreach($gcp in $gcps)
{
if ($gcp.StartsWith("#"))
{
Write-Debug "$gcp skipped..."
}
else
{
Write-host "Rebooting $gcp"
Invoke-Command -computername $gcp -scriptblock { shutdown /r /t 0}
}
}
Read-Host -Prompt "Update Complete - Press enter to close"