-
Notifications
You must be signed in to change notification settings - Fork 127
/
ConfigMgrRebootReport.ps1
52 lines (44 loc) · 1.76 KB
/
ConfigMgrRebootReport.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
<#
.SYNOPSIS
ConfigMgr Reboot Report
.DESCRIPTION
This script will query ConfigMgr for a list of machines that are waiting for a reboot.
.PARAMETER Collection
Name of the collection to query
.PARAMETER SQLServer
Name of the SQL server
.PARAMETER SQLDatabase
A description of the SQLDatabase parameter.
.PARAMETER SQLInstance
Name of the SQL Database
.PARAMETER SCCMFQDN
Fully Qualified Domain Name of the ConfigMgr server
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2017 v5.4.142
Created on: 05/01/2020 09:39 AM
Created by: Mick Pletcher
Filename: ConfigMgrRebootReport.ps1
===========================================================================
#>
[CmdletBinding()]
param
(
[ValidateNotNullOrEmpty()]
[string]$Collection = '',
[ValidateNotNullOrEmpty()]
[string]$SQLServer = '',
[ValidateNotNullOrEmpty()]
[string]$SQLDatabase = ''
)
$RebootListQuery = 'SELECT * FROM dbo.vSMS_CombinedDeviceResources WHERE ClientState <> 0'
$RebootList = (Invoke-Sqlcmd -ServerInstance $SQLServer -Database $SQLDatabase -Query $RebootListQuery).Name | Sort-Object
$CollectionQuery = 'SELECT * FROM' + [char]32 + 'dbo.' + ((Invoke-Sqlcmd -ServerInstance $SQLServer -Database $SQLDatabase -Query ('SELECT ResultTableName FROM dbo.v_Collections WHERE CollectionName = ' + [char]39 + $Collection + [char]39)).ResultTableName)
$CollectionList = (Invoke-Sqlcmd -ServerInstance $SQLServer -Database $SQLDatabase -Query $CollectionQuery).Name | Sort-Object
$List = @()
$RebootList | ForEach-Object { If ($_ -in $CollectionList) { $List += $_ } }
If ($List -ne '') {
Write-Output $List
} else {
Exit 1
}