-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminService-GridViewDemo.ps1
226 lines (167 loc) · 6.05 KB
/
AdminService-GridViewDemo.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
#https://lazywinadmin.com/2015/09/powershellsccm-find-applications.html
#https://setupconfigmgr.com/how-to-configure-microsoft-sccm-to-use-https-pki
#https://docs.microsoft.com/en-us/graph/query-parameters
#https://www.petervanderwoude.nl/post/install-user-targeted-applications-during-os-deployment-via-powershell-and-configmgr-2012/
#E:\Program Files\Microsoft Configuration Manager\bin\X64\CMRestProvider\AdminService.Host\adminservice.host.dll
<#
#URL Format Options
<ClassName>('KeyValue') - only works for key properties
<ClassName>?$filter=<PropertyName> <Operator> <PropertyValue>
<ClassName>?$filter=<PropertyName>%20<Operator>%20<PropertyValue>
<ClassName>?$filter=<PropertyName> <Operator> <PropertyValue>
EXAMPLE - https://<FQDN>/AdminService/wmi/Collection?$filter=CollectionType%20eq%201 - searches for all collections with CollectionType being 1.
EXAMPLE - https://<FQDN>/AdminService/wmi/Collection?$filter=CollectionType eq 1
OPERATORS
$path
$filter
$orderby
$select;
$expand;
$skip;
$top;
$inlineCount
$format
any all
#>
Function StringBuilder {
[CmdletBinding()]
param(
[string]
$PropertyName,
[string]
$PropertyValue,
[ValidateSet(
'filter',
'any',
'all',
'cast',
'ceiling',
'concat',
'contains',
'day',
'endswith',
'floor',
'hour',
'indexof',
'isof',
'length',
'minute',
'month',
'round',
'second',
'startswith',
'substring',
'tolower',
'toupper',
'trim',
'year',
'date',
'time',
'fractionalseconds'
)]
[string]
$Function,
[string]
[ValidateSet("eq","ne")]
$Operator,
[switch]
$quote
)
$ReturnValue = $null
If($quote) {
$PropertyValue = "'{0}'" -f $PropertyValue
}
$ReturnValue = "`${0}={1}%20{2}%20{3}" -f $Function,$PropertyName,$Operator,$PropertyValue
Write-Host $ReturnValue | Out-Null
Return $ReturnValue
}
$ComputerName = 'CM01'
$Script:WMIBaseURI = "https://CM01.ASD.NET:443/AdminService/wmi/"
Function Get-WMIResults($URI)
{
$FullURI = "$($Script:WMIBaseURI)$($URI)"
Write-Host $FullURI
$Results = Invoke-RestMethod -Method get -Uri $FullURI -UseDefaultCredentials
Return $Results
}
#####################################################################
#Get DeviceList
$URI = "Device"
$Results = Get-WMIResults -URI $URI
$DeviceList = $Results.Value
$SelectedDevice = $DeviceList | Select-Object * | Out-GridView -Title "Select A Device" -OutputMode Single
If(!([string]::IsNullOrEmpty($SelectedDevice)))
{
$SelectedDevice | Select-Object *
#break;
}
else {
Break;
}
#Get WMI Function List
$URI = "$metadata"
$Results = Get-WMIResults -URI $URI
$WMIFunctionList = $Results.Value
$ClickResult = $WMIFunctionList | Select-Object * | Out-GridView -Title "AdminService WMI Function List" -OutputMode Single
$URI = "Device($($SelectedDevice.ResourceId))/$($ClickResult.Name)"
$Results = Get-WMIResults -URI $URI
$Results.Value | Select-Object * | Out-GridView
break;
#####################################################################
##############################################################
#Get Device Not Equal to CM01 and Select Name only
$URI = "Device?`$filter=Name ne 'CM01'&`$select=Name"
$Results = Get-WMIResults -URI $URI
$Results.Value
#Get Top 2 Devices
$URI = 'Device?$top=2'
$Results = Get-WMIResults -URI $URI
#$Results.Value
$Results.Value.Name
#Find Primary User
$URI = "UserMachineRelationship?`$filter=ResourceName eq 'CM01'"
$Results = Get-WMIResults -URI $URI
$Results.Value
##############################################################
##############################################################
#Get Device
$Filter = StringBuilder -PropertyName "Name" -PropertyValue $ComputerName -Function filter -Operator eq -quote
#$URI = "Device?{0}&select=ResourceId"-f $Filter
$URI = "Device?{0}"-f $Filter
$Results = Get-WMIResults -URI $URI
$Device = $Results.Value
Write-Host ("The Destination Computer Name is: {0} and ResourceID is: {1}" -f $Device.Name,$Device.ResourceID)
#Get Source Computer Name
$Filter = StringBuilder -PropertyName "RestoreClientResourceID" -PropertyValue $Device.ResourceId -Function filter -Operator eq
$URI = "StateMigration?{0}&`$select=SourceName,SourceClientResourceID" -f $filter
$Results = Get-WMIResults -URI $URI
$SourceDevice = $Results.Value
Write-Host ("The Source Computer Name is: {0} and ResourceID is:{1}" -f $SourceDevice.SourceName,$SourceDevice.SourceClientResourceID)
#Collection Membership for SourceComputer
$Filter = StringBuilder -PropertyName "ResourceID" -PropertyValue $SourceDevice.SourceClientResourceID -Function filter -Operator eq
$URI = "FullCollectionMembership?{0}"-f $Filter
$Results = Get-WMIResults -URI $URI
$SourceComputerCollectionList = $Results.Value
$Collections = $SourceComputerCollectionList
[string[]]$AddList = $null
#Application AdministativeCategories
$Filter = StringBuilder -PropertyName "CategoryTypeName" -PropertyValue 'AppCategories' -Function filter -Operator eq -quote
$URI = "CategoryInstance?{0}"-f $Filter
$Results = Get-WMIResults -URI $URI
$AppCategories = $Results.Value
ForEach($Collection in $Collections) {
#Application Advertisements
$Filter = StringBuilder -PropertyName "TargetCollectionID" -PropertyValue $Collection.CollectionID -Function filter -Operator eq -quote
$URI = "ApplicationAssignment?{0}"-f $Filter
$Results = Get-WMIResults -URI $URI
$Deployment = $Results.Value
If($Results.Value)
{
Write-Host ("CollectionID {0} has Application {1} Deployed to It. Adding collection to list." -f $Collection.CollectionID, $Deployment.Name)
$AddList.Add($Collection)
}
}
#Application Advertisements
$URI = "Application"
$Results = Get-WMIResults -URI $URI
$Results.Value