This repository has been archived by the owner on Nov 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathSCCM_Client.psm1
270 lines (233 loc) · 8.27 KB
/
SCCM_Client.psm1
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
<#
.SYNOPSIS
Allows triggering of SCCM client actions.
.DESCRIPTION
Takes in a computer name and an action id, and attempts to trigger it remotely.
.PARAMETER scheduleId
The available schedule ids are:
HardwareInventory
SoftwareInventory
DataDiscovery
MachinePolicyRetrievalEvalCycle
MachinePolicyEvaluation
RefreshDefaultManagementPoint
RefreshLocation
SoftwareMeteringUsageReporting
SourcelistUpdateCycle
RefreshProxyManagementPoint
CleanupPolicy
ValidateAssignments
CertificateMaintenance
BranchDPScheduledMaintenance
BranchDPProvisioningStatusReporting
SoftwareUpdateDeployment
StateMessageUpload
StateMessageCacheCleanup
SoftwareUpdateScan
SoftwareUpdateDeploymentReEval
OOBSDiscovery
#>
Function Invoke-SCCMClientAction {
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=0)]
[ValidateNotNull()]
[string]
$computerName,
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNull()]
[string]
$scheduleId
)
$scheduleIdList = @{
HardwareInventory = "{00000000-0000-0000-0000-000000000001}";
SoftwareInventory = "{00000000-0000-0000-0000-000000000002}";
DataDiscovery = "{00000000-0000-0000-0000-000000000003}";
MachinePolicyRetrievalEvalCycle = "{00000000-0000-0000-0000-000000000021}";
MachinePolicyEvaluation = "{00000000-0000-0000-0000-000000000022}";
RefreshDefaultManagementPoint = "{00000000-0000-0000-0000-000000000023}";
RefreshLocation = "{00000000-0000-0000-0000-000000000024}";
SoftwareMeteringUsageReporting = "{00000000-0000-0000-0000-000000000031}";
SourcelistUpdateCycle = "{00000000-0000-0000-0000-000000000032}";
RefreshProxyManagementPoint = "{00000000-0000-0000-0000-000000000037}";
CleanupPolicy = "{00000000-0000-0000-0000-000000000040}";
ValidateAssignments = "{00000000-0000-0000-0000-000000000042}";
CertificateMaintenance = "{00000000-0000-0000-0000-000000000051}";
BranchDPScheduledMaintenance = "{00000000-0000-0000-0000-000000000061}";
BranchDPProvisioningStatusReporting = "{ 00000000-0000-0000-0000-000000000062}";
SoftwareUpdateDeployment = "{00000000-0000-0000-0000-000000000108}";
StateMessageUpload = "{00000000-0000-0000-0000-000000000111}";
StateMessageCacheCleanup = "{00000000-0000-0000-0000-000000000112}";
SoftwareUpdateScan = "{00000000-0000-0000-0000-000000000113}";
SoftwareUpdateDeploymentReEval = "{00000000-0000-0000-0000-000000000114}";
OOBSDiscovery = "{00000000-0000-0000-0000-000000000120}";
}
return Invoke-SCCMClientSchedule $computerName $scheduleIdList.$scheduleId
}
<#
.SYNOPSIS
Allows triggering of SCCM client scheduled messages.
.DESCRIPTION
Takes in a computer name and an scheduled message id, and attempts to trigger it remotely.
#>
Function Invoke-SCCMClientSchedule {
[CmdletBinding()]
param(
[parameter(Mandatory=$true, Position=0)]
[ValidateNotNull()]
[string]
$computerName,
[Parameter(Mandatory=$true, Position=1)]
[ValidateNotNull()]
[string]
$scheduleId
)
$sccmClient = [WMIclass]"\\$computerName\root\ccm:SMS_Client"
return $sccmClient.TriggerSchedule($scheduleId)
}
<#
.SYNOPSIS
Contacts a client computer to obtain its software distribution history.
.DESCRIPTION
Takes in a computer name and attempts to contact it to obtain information about its software distribution history.
The information comes from the CCM_SoftwareDistribution WMI class which according to the Microsoft documentation is a "class
that stores information specific to a software distribution, a combination of the properties for the package, program, and advertisement
that were created to distribute the software."
.PARAMETER computerName
The name of the client to be contacted in order to retrieve the advertisement history.
.EXAMPLE
Get-SCCMSoftwareDistributionHistory -computerName MYCOMPUTER
.NOTES
http://msdn.microsoft.com/en-us/library/cc145304.aspx
#>
Function Get-SCCMClientSoftwareDistributionHistory {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateNotNull()]
[string]
$computerName
)
return Get-WMIObject -Computer $computerName -Namespace "root\CCM\Policy\Machine\ActualConfig" -Query "Select * from CCM_SoftwareDistribution"
}
<#
.SYNOPSIS
Returns the schedule ID for a specific advertisement on a specific client.
.DESCRIPTION
Takes in a computer name and an advertisement ID and contacts a client to find out the schedule ID for the advertisement.
Useful when trying to trigger and advertisement on demand.
#>
Function Get-SCCMClientAdvertisementScheduleId {
[CmdletBinding()]
param (
[parameter(Mandatory=$true, Position=0)]
[ValidateNotNull()]
[string]
$computerName,
[parameter(Mandatory=$true, Position=1)]
[ValidateLength(8,8)]
[string]
$advertisementId
)
$scheduledMessages = Get-WMIObject -Computer $computerName -Namespace "root\CCM\Policy\Machine\ActualConfig" -Query "Select * from CCM_Scheduler_ScheduledMessage"
foreach($scheduledMessage in $scheduledMessages) {
if($($scheduledMessage.ScheduledMessageID).Contains($advertisementId)) {
return $scheduledMessage.ScheduledMessageID
}
}
return $null
}
<#
.SYNOPSIS
Returns the ssite code of a specific client computer.
.DESCRIPTION
Takes in a computer name and contacts the client to determine its assigned site code.
#>
Function Get-SCCMClientAssignedSite {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateNotNull()]
[string]
$computerName
)
$sccmClient = [WMIclass]"\\$computerName\root\ccm:SMS_Client"
return $($sccmClient.GetAssignedSite()).sSiteCode
}
<#
.SYNOPSIS
Assignes a new site code to a specific client computer.
.DESCRIPTION
Takes in a computer name and contacts the client to set its assigned site code.
#>
Function Set-SCCMClientAssignedSite {
[CmdletBinding()]
param (
[parameter(Mandatory=$true, Position=0)]
[ValidateNotNull()]
[string]
$computerName,
[parameter(Mandatory=$true, Position=1)]
[ValidateLength(3,3)]
[string]
$siteCode
)
$sccmClient = [WMIclass]"\\$computerName\root\ccm:SMS_Client"
return $sccmClient.SetAssignedSite($siteCode)
}
<#
.SYNOPSIS
Retrieves a client computer's cache size.
.DESCRIPTION
Contacts a client computer to retrieve information about its cache size. The value returned represents the cache size in MB.
.PARAMETER computerName
Name of the computer to be contacted.
.EXAMPLE
Get-SCCMClientCacheSize -computerName MYCOMPUTER
Description
-----------
Returns the client computer's cache size in MB.
#>
Function Get-SCCMClientCacheSize {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateNotNull()]
[string]
$computerName
)
$cacheConfig = Get-WMIObject -Computer $computerName -Namespace "root\CCM\SoftMgmtAgent" -Query "Select * From CacheConfig"
return $cacheConfig.Size
}
<#
.SYNOPSIS
Changes the cache size for a client computer.
.DESCRIPTION
Contacts a client computer to change its cache size. The value won't be picked up by the SCCM client on the target computer
until the CcmExec service is restarted. This function does not attempt to restart the service.
.PARAMETER computerName
Name of the computer to be contacted.
.PARAMETER cacheSize
The new size of the computer's cache in MB. This value must be greater than 0.
.EXAMPLE
Set-SCCMClientCacheSize -computerName MYCOMPUTER -cacheSize 1000
Description
-----------
Sets the client computer's cache size to 1000MB.
#>
Function Set-SCCMClientCacheSize {
[CmdletBinding()]
param (
[parameter(Mandatory=$true, Position=0)]
[ValidateNotNull()]
[string]
$computerName,
[parameter(Mandatory=$true, Position=1)]
[ValidateScript( { $_ -gt 0 } )]
[int]
$cacheSize
)
$cacheConfig = Get-WMIObject -Computer $computerName -Namespace "root\CCM\SoftMgmtAgent" -Query "Select * From CacheConfig"
$cacheConfig.Size = $cacheSize
$cacheConfig.Put() | Out-Null
}