-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-PendingClients.ps1
334 lines (293 loc) · 8.2 KB
/
Get-PendingClients.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
Function Get-PendingClients {
<#
.SYNOPSIS
generate a report for all devices in a collection that does not have a client installed.
.DESCRIPTION
This function has been designed to collate all clients without a client and export them into a report.
.EXAMPLE
Get-PendingClients -SiteCode AB1 -ProviderMachineName "SCCMServer" -Collection "Example Collection" -Export "C:\system center"
.EXAMPLE
Get-PendingClients -SiteCode AB1 -ProviderMachineName "SCCMServer" -Collection "Example Collection 1", "Example Collection 2" -Export "C:\ExportPath"
.NOTES
File Name : Get-PendingClients.ps1
Author : Sam Reece
Requires : System Center Configuration Manager
Version : 1.0.3
GitHub : https://github.com/SamReece/System-Centre
#>
param
(
[Parameter(Mandatory=$true)][String]$SiteCode,
[Parameter(Mandatory=$true)][String]$ProviderMachineName,
[Parameter(Mandatory=$true)][String[]]$Collection,
[Parameter(Mandatory=$true)][String[]]$Export,
[Parameter(Mandatory=$false)][String[]]$Title
)
$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
$Date = Get-Date -Format "dd-MM-yy "
$Time = Get-Date -Format "HH:mm"
$header = @"
<head>
<title>IT Department</title>
<style>
body {
background-color: #ffffff;
font-family: "Roboto", helvetica, arial, sans-serif;
font-size: 10px;
font-weight: 400;
text-rendering: optimizeLegibility;
}
div.table-title {
display: block;
margin: auto;
max-width: 600px;
padding:5px;
width: 100%;
}
.header {
background-color: #292c2f;
padding: 20px;
text-align: center;
color: #8d9093;
font-size: 16px;
margin: 0;
}
.summary {
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
padding-left: 10px;
height: 100px;
width: 900px;
position: relative;
border-style:solid;
border-radius: 12px;
border-color:lightgray;
border-width: 1px;
font-size: 14px;
font-family: 'Open sans', sans-serif;
color: #777777;
}
.table-title h3 {
color: #fafafa;
font-size: 20px;
font-weight: 200;
font-style:normal;
font-family: "Roboto", helvetica, arial, sans-serif;
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
text-transform:uppercase;
}
/*** Table Styles **/
.table-fill {
background: white;
border-radius:3px;
border-collapse: collapse;
height: 320px;
margin: auto;
max-width: 600px;
padding:5px;
width: 100%;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
animation: float 5s infinite;
}
th {
color:#D5DDE5;;
background:#1b1e24;
border-bottom:4px solid #9ea7af;
border-right: 1px solid #343a45;
font-size:1810:52 26/07/2018px;
font-weight: 100;
padding:10px;
text-align:left;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
vertical-align:middle;
}
th:first-child {
border-top-left-radius:3px;
}
th:last-child {
border-top-right-radius:3px;
border-right:none;
}
tr {
border-top: 1px solid #C1C3D1;
border-bottom-: 1px solid #C1C3D1;
color:#666B85;
font-size:12px;
font-weight:normal;
text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
}
tr:hover td {
background:#4E5066;
color:#FFFFFF;
border-top: 1px solid #22262e;
border-bottom: 1px solid #22262e;
}
tr:first-child {
border-top:none;
}
tr:last-child {
border-bottom:none;
}
tr:nth-child(odd) td {
background:#EBEBEB;
}
tr:nth-child(odd):hover td {
background:#4E5066;
}
tr:last-child td:first-child {
border-bottom-left-radius:3px;
}
tr:last-child td:last-child {
border-bottom-right-radius:3px;
}
td {
background:#FFFFFF;
padding:20px;
text-align:left;
vertical-align:middle;
font-weight:300;
font-size:12px;
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
border-right: 1px solid #C1C3D1;
}
td:last-child {
border-right: 0px;
}
th.text-left {
text-align: left;
}
th.text-center {
text-align: center;
}
th.text-right {
text-align: right;
}
td.text-left {
text-align: left;
}
td.text-center {
text-align: center;
}
td.text-right {
text-align: right;
}
/*** Footer styles ***/
.footer-basic-centered{
background-color: #292c2f;
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.12);
box-sizing: border-box;
width: 100%;
text-align: center;
font: normal 18px sans-serif;
padding: 45px;
margin-top: 80px;
}
.footer-basic-centered .footer-Department{
color: #8d9093;
font-size: 24px;
margin: 0;
}
.footer-basic-centered .footer-Generated{
color: #8f9296;
font-size: 14px;
margin: 0;
}
.footer-basic-centered .footer-links{
list-style: none;
font-weight: bold;
color: #ffffff;
padding: 35px 0 23px;
margin: 0;
}
.footer-basic-centered .footer-links a{
display:inline-block;
text-decoration: none;
color: inherit;
}
</style>
"@
$Report = '
</style>
<div class="header">
<H1>IT Department</H1>
</div>
'
if (-not $Title) {
$Title = "Pending Clients"
}
$Report += "<H2>Report type: $Title</H2>"
$Path = (Test-Path -Path $Export)
if (-Not $Export) {
Write-host "$Export path does not exist" -ForegroundColor Red
break
}
# Connectivty and query code
$initParams = @{}
if((Get-Module ConfigurationManager) -eq $null) {
Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams
}
if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) {
New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams
}
Set-Location "$($SiteCode):\" @initParams
Foreach ($DeviceCollection in $Collection) {
$Name = "<H3>$DeviceCollection</H3>"
$Devices = (Get-CMDevice -CollectionName "$DeviceCollection")
$Output = New-Object System.Collections.ArrayList
Foreach ($Device in $Devices) {
if (-not $Device.ClientType) {
$Deviceinfo = New-Object psobject
$Online = (Test-NetConnection $Device.Name -Hops 1)
if (-Not $Online.PingSucceeded) {
$RPC = $False
}
else { $RPC = Get-WMIObject -Class Win32_OperatingSystem -ComputerName $Device.Name }
if (-Not [bool]$RPC) {
$WMI = $False
}
else { $WMI = $True }
$Deviceinfo | Add-Member -MemberType NoteProperty -Name "Computer" -Value $Device.Name
$Deviceinfo | Add-Member -MemberType NoteProperty -Name "Client" -Value "No"
$Deviceinfo | Add-Member -MemberType NoteProperty -Name "ICMP" -Value "$($Online.PingSucceeded)"
$Deviceinfo | Add-Member -MemberType NoteProperty -Name "WMI Enabled" -Value $WMI
$Output += $Deviceinfo
$Conversion = $Output | ConvertTo-Html
}
}
$Report += $Name
$Report += " "
if ($null -eq $Conversion) {
$Report += '<b Style="font-size: 14px; color: green;">No data</b>'
$Report += " "
$Report += "<h2> Report Summary for $DeviceCollection</h2>"
$Report += " "
$Report += '<b Style="font-size: 14px; color: green;">All client machines in' + " $DeviceCollection have been installed </b>"
}
else{
$ICMPCount = $Output."ICMP" | where {$_ -eq "False"}
$WMICount = $Output."WMI Enabled" | where {$_ -eq $False}
$Report += $Conversion
$Report += " "
$Report += " "
$Report += "<h2> Report Summary:</h2>"
$Report += '<p class="summary">' +"There are $($Output.Computer.Count) computers and servers in $Collection that do not have the System Center client installed on the host.`n<br>
<br>$($Output.Computer.Count) devices in $Collection, $($ICMPCount.count) are unreachable by ping.`n<br>
<br>$($WMICount.Count) devices are unavailable by WMI (Remote Procedure Call) Turn off the firewall or redeploy the group GPO</p>"}
}
$Stopwatch.Stop()
$Report += @"
<footer class="footer-basic-centered">
<p class="footer-Department">Group IT department</p>
<p class="footer-links">
<a href="mailto:samreece@protonmail.com">Contact</a>
</p>
<p class="footer-Generated">Generated on: $Time $Date</p>
<p class="footer-Generated"> Script duration: $($Stopwatch.Elapsed.seconds) seconds</p>
</footer>
"@
ConvertTo-Html -head $header -Body $Report | Out-File "$Export\$Collection - $Title.html"
Invoke-Item "$Export\$Collection - $Title.html"
}