Repository navigation
Expand file tree
/
Copy pathCheatSheet-CM.html
More file actions
325 lines (321 loc) · 14.8 KB
/
Copy pathCheatSheet-CM.html
File metadata and controls
325 lines (321 loc) · 14.8 KB
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
<h1 id="powershell-cheat-sheet-configuration-manager">PowerShell Cheat Sheet - Configuration Manager</h1>
<h2 id="initial-setup"><strong>Initial Setup</strong></h2>
<ul>
<li><p><strong>Import the SCCM PowerShell Module</strong></p>
<pre><code class="language-powershell">Import-Module "$($env:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1"
</code></pre>
</li>
<li><p><strong>Set the SCCM Site Code</strong> – Replace <code>XYZ</code> with your specific site code.</p>
<pre><code class="language-powershell">$SiteCode = "XYZ"
cd "$SiteCode:"
</code></pre>
</li>
</ul>
<h2 id="collections-management"><strong>Collections Management</strong></h2>
<ul>
<li><p><strong>List All Collections</strong> (Device & User)</p>
<pre><code class="language-powershell">Get-CMCollection
</code></pre>
</li>
<li><p><strong>Get Detailed Information About a Collection</strong></p>
<pre><code class="language-powershell">Get-CMDeviceCollection -Name "CollectionName" | Select-Object *
</code></pre>
</li>
<li><p><strong>List All Devices in a Collection</strong></p>
<pre><code class="language-powershell">Get-CMDeviceCollectionMember -CollectionName "CollectionName"
</code></pre>
</li>
</ul>
<h2 id="device-management"><strong>Device Management</strong></h2>
<ul>
<li><p><strong>List All Devices with Extended Properties</strong></p>
<pre><code class="language-powershell">Get-CMDevice | Select-Object Name, DeviceID, ResourceID, SMSAssignedSites, AgentEdition, ClientVersion
</code></pre>
</li>
<li><p><strong>Get Device by MAC Address</strong></p>
<pre><code class="language-powershell">Get-CMDevice -MACAddress "00-1A-2B-3C-4D-5E"
</code></pre>
</li>
</ul>
<h2 id="application-management"><strong>Application Management</strong></h2>
<ul>
<li><p><strong>List All Applications with Additional Details</strong></p>
<pre><code class="language-powershell">Get-CMApplication | Select-Object LocalizedDisplayName, SoftwareVersion, Manufacturer, DeploymentType
</code></pre>
</li>
<li><p><strong>Get Detailed Information About an Application</strong></p>
<pre><code class="language-powershell">Get-CMApplication -Name "AppName" | Select-Object *
</code></pre>
</li>
<li><p><strong>Modify Application Deployment Type</strong></p>
<pre><code class="language-powershell">Set-CMDeploymentType -ApplicationName "AppName" -DeploymentTypeName "AppDeploymentType" -InstallCommand "NewInstallCommand"
</code></pre>
</li>
<li><p><strong>Delete an Application</strong></p>
<pre><code class="language-powershell">Remove-CMApplication -Name "AppName"
</code></pre>
</li>
</ul>
<h2 id="package-program-management"><strong>Package & Program Management</strong></h2>
<ul>
<li><p><strong>Create a Package</strong></p>
<pre><code class="language-powershell">New-CMPackage -Name "PackageName" -Path "\\Server\Share\Source" -Description "Package for testing"
</code></pre>
</li>
<li><p><strong>Create a Program for a Package</strong></p>
<pre><code class="language-powershell">New-CMProgram -PackageName "PackageName" -StandardProgramName "ProgramName" -CommandLine "setup.exe /silent" -Description "Silent Install Program"
</code></pre>
</li>
<li><p><strong>Deploy a Package to a Collection</strong></p>
<pre><code class="language-powershell">Start-CMPackageDeployment -PackageName "PackageName" -CollectionName "CollectionName" -DeploymentType Required
</code></pre>
</li>
</ul>
<h2 id="deployment-management"><strong>Deployment Management</strong></h2>
<ul>
<li><p><strong>List All Application Deployments</strong></p>
<pre><code class="language-powershell">Get-CMApplicationDeployment
</code></pre>
</li>
<li><p><strong>Get Deployment Details for a Specific Application</strong></p>
<pre><code class="language-powershell">Get-CMApplicationDeployment -Name "AppName"
</code></pre>
</li>
<li><p><strong>Update Deployment Properties</strong></p>
<pre><code class="language-powershell">Set-CMDeployment -DeploymentID <DeploymentID> -NewDeadline $((Get-Date).AddDays(7))
</code></pre>
</li>
<li><p><strong>Monitor Deployment Status</strong></p>
<pre><code class="language-powershell">Get-CMDeploymentStatus -Name "AppName" -CollectionName "CollectionName"
</code></pre>
</li>
<li><p><strong>Delete an Application Deployment</strong></p>
<pre><code class="language-powershell">Remove-CMDeployment -DeploymentID <DeploymentID>
</code></pre>
</li>
</ul>
<h2 id="software-update-management"><strong>Software Update Management</strong></h2>
<ul>
<li><p><strong>List All Software Updates with Details</strong></p>
<pre><code class="language-powershell">Get-CMSoftwareUpdate | Select-Object ArticleID, Title, DatePosted, IsDeployed
</code></pre>
</li>
<li><p><strong>Synchronize Software Updates</strong></p>
<pre><code class="language-powershell">Sync-CMSoftwareUpdate
</code></pre>
</li>
<li><p><strong>Create a Software Update Group</strong></p>
<pre><code class="language-powershell">New-CMSoftwareUpdateGroup -Name "UpdateGroupName"
</code></pre>
</li>
<li><p><strong>Add Updates to Software Update Group</strong></p>
<pre><code class="language-powershell">Add-CMSoftwareUpdateToGroup -SoftwareUpdateGroupName "UpdateGroupName" -SoftwareUpdateIDs <UpdateID1>, <UpdateID2>
</code></pre>
</li>
<li><p><strong>Deploy Software Update Group to Collection</strong></p>
<pre><code class="language-powershell">Start-CMSoftwareUpdateDeployment -DeploymentName "UpdateDeployment" -SoftwareUpdateGroupName "UpdateGroupName" -CollectionName "CollectionName" -Deadline ((Get-Date).AddDays(3))
</code></pre>
</li>
</ul>
<h2 id="compliance-baseline-management"><strong>Compliance & Baseline Management</strong></h2>
<ul>
<li><p><strong>Get All Compliance Settings</strong></p>
<pre><code class="language-powershell">Get-CMComplianceSetting
</code></pre>
</li>
</ul>
<h2 id="task-sequence-management"><strong>Task Sequence Management</strong></h2>
<ul>
<li><p><strong>List All Task Sequences with Details</strong></p>
<pre><code class="language-powershell">Get-CMTaskSequence | Select-Object Name, PackageID, LastModified
</code></pre>
</li>
<li><p><strong>Copy an Existing Task Sequence</strong></p>
<pre><code class="language-powershell">Copy-CMTaskSequence -TaskSequenceName "OriginalTaskSequence" -NewTaskSequenceName "CopiedTaskSequence"
</code></pre>
</li>
<li><p><strong>Edit Task Sequence Variable</strong></p>
<pre><code class="language-powershell">Set-CMTaskSequenceVariable -TaskSequenceName "TaskSequenceName" -VariableName "TSVar" -Value "NewValue"
</code></pre>
</li>
<li><p><strong>Delete a Task Sequence</strong></p>
<pre><code class="language-powershell">Remove-CMTaskSequence -Name "TaskSequenceName"
</code></pre>
</li>
</ul>
<h2 id="client-actions"><strong>Client Actions</strong></h2>
<ul>
<li><p><strong>Trigger a Software Update Scan</strong></p>
<pre><code class="language-powershell">Invoke-CMClientAction -DeviceName "DeviceName" -Action "SoftwareUpdatesScanCycle"
</code></pre>
</li>
<li><p><strong>Initiate User Policy Retrieval</strong></p>
<pre><code class="language-powershell">Invoke-CMClientAction -DeviceName "DeviceName" -Action "RequestUserPolicy"
</code></pre>
</li>
<li><p><strong>Force Application Deployment Evaluation</strong></p>
<pre><code class="language-powershell">Invoke-CMClientAction -DeviceName "DeviceName" -Action "ApplicationDeploymentEvaluationCycle"
</code></pre>
</li>
</ul>
<h2 id="monitoring-reporting"><strong>Monitoring & Reporting</strong></h2>
<ul>
<li><p><strong>Get All Status Messages for a Deployment</strong></p>
<pre><code class="language-powershell">Get-CMStatusMessage -DeploymentID <DeploymentID> | Select-Object MessageID, Component, MessageType, SiteCode
</code></pre>
</li>
<li><p><strong>View Compliance Summary for a Collection</strong></p>
<pre><code class="language-powershell">Get-CMComplianceSummaryReport -CollectionName "CollectionName"
</code></pre>
</li>
<li><p><strong>Get Deployment Success Rate for a Collection</strong></p>
<pre><code class="language-powershell">Get-CMDeploymentStatus -Name "AppName" -CollectionName "CollectionName" | Select-Object Name, EnforcementState, LastComplianceMessage
</code></pre>
</li>
<li><p><strong>Export Report to CSV</strong></p>
<pre><code class="language-powershell">Get-CMStatusMessage -CollectionName "CollectionName" | Export-Csv -Path "C:\StatusMessages.csv" -NoTypeInformation
</code></pre>
</li>
</ul>
<h2 id="queries"><strong>Queries</strong></h2>
<p>Queries in SCCM help identify and organize resources based on criteria. Below are some PowerShell commands to create, retrieve, and work with queries.</p>
<ul>
<li><p><strong>List All Queries</strong></p>
<pre><code class="language-powershell">Get-CMQuery
</code></pre>
</li>
<li><p><strong>Get Query Details by Name</strong></p>
<pre><code class="language-powershell">Get-CMQuery -Name "QueryName" | Select-Object *
</code></pre>
</li>
<li><p><strong>Create a New Query</strong> – Creates a device query based on a simple attribute.</p>
<pre><code class="language-powershell">New-CMQuery -Name "Windows 10 Devices" -CollectionName "All Systems" -QueryExpression "<br />select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.Name<br />from SMS_R_System<br />where SMS_R_System.OperatingSystemNameandVersion like 'Microsoft Windows NT Workstation 10.0%'"
</code></pre>
</li>
<li><p><strong>Modify an Existing Query</strong></p>
<pre><code class="language-powershell">Set-CMQuery -Name "QueryName" -NewQueryExpression "<br />select * from SMS_R_System<br />where SMS_R_System.LastLogonTimestamp >= (Get-Date).AddDays(-30)"
</code></pre>
</li>
<li><p><strong>Delete a Query</strong></p>
<pre><code class="language-powershell">Remove-CMQuery -Name "QueryName"
</code></pre>
</li>
</ul>
<h2 id="reports"><strong>Reports</strong></h2>
<p>Reports in SCCM provide data-driven insights into your environment. Here’s how to manage and run SCCM reports with PowerShell.</p>
<ul>
<li><p><strong>List All Reports</strong></p>
<pre><code class="language-powershell">Get-CMReport
</code></pre>
</li>
<li><p><strong>Get Report Details</strong></p>
<pre><code class="language-powershell">Get-CMReport -Name "ReportName" | Select-Object *
</code></pre>
</li>
<li><p><strong>Run a Report and Export Results to CSV</strong> – Running reports directly via PowerShell typically returns metadata, but you can use SQL queries to extract data if direct data output is needed.</p>
<pre><code class="language-powershell">Invoke-Sqlcmd -Query "SELECT * FROM v_ReportViewName" -ServerInstance "SQLServerInstance" | Export-Csv -Path "C:\ReportResults.csv" -NoTypeInformation
</code></pre>
</li>
<li><p><strong>Create a Report Folder</strong></p>
<pre><code class="language-powershell">New-CMReportFolder -Name "CustomReports" -ParentFolderID 5000 # Replace with appropriate ParentFolderID
</code></pre>
</li>
<li><p><strong>Create a New Report</strong> – Requires SQL query; adjust parameters as necessary.</p>
<pre><code class="language-powershell">New-CMReport -Name "Custom Report" -CategoryID 1 -SQLQuery "SELECT * FROM v_R_System"
</code></pre>
</li>
<li><p><strong>Delete a Report</strong></p>
<pre><code class="language-powershell">Remove-CMReport -Name "ReportName"
</code></pre>
</li>
</ul>
<h2 id="user-device-affinity"><strong>User-Device Affinity</strong></h2>
<p>User-device affinity (UDA) in SCCM establishes relationships between users and devices, helping target deployments or configurations to primary devices associated with specific users.</p>
<ul>
<li><p><strong>View User Affinity for a Device</strong></p>
<pre><code class="language-powershell">Get-CMUserAffinity -DeviceName "DeviceName"
</code></pre>
</li>
<li><p><strong>View Device Affinity for a User</strong></p>
<pre><code class="language-powershell">Get-CMUserAffinity -UserName "UserName"
</code></pre>
</li>
<li><p><strong>Add User-Device Affinity</strong> – Creates a direct user-device affinity.</p>
<pre><code class="language-powershell">New-CMUserAffinity -UserName "UserName" -DeviceName "DeviceName" -PrimaryUsage $true
</code></pre>
</li>
<li><p><strong>Remove User-Device Affinity</strong> – Removes an established user-device relationship.</p>
<pre><code class="language-powershell">Remove-CMUserAffinity -UserName "UserName" -DeviceName "DeviceName"
</code></pre>
</li>
<li><p><strong>List All Devices with Affinity for a User</strong> – Lists devices where the user is marked as primary.</p>
<pre><code class="language-powershell">Get-CMUserAffinity -UserName "UserName" | Where-Object { $_.PrimaryUsage -eq $true }
</code></pre>
</li>
<li><p><strong>Automatically Create User-Device Affinity Based on Usage</strong> – Configure settings in SCCM to allow automatic UDA creation based on user login history.</p>
<pre><code class="language-powershell"># This setting needs to be configured within the SCCM console under Administration -> Client Settings -> Default Client Settings -> User and Device Affinity
</code></pre>
</li>
</ul>
<script src="prism.js"></script>
<link href="prism.css" rel="stylesheet" />
<script>
document.querySelectorAll("code").forEach((codeElement) => {
// Replace each pipe character with a span-wrapped version
codeElement.innerHTML = codeElement.innerHTML.replace(/\|/g, '|<br />');
codeElement.innerHTML = codeElement.innerHTML.replace(/ -/g, ' <wbr />-');
codeElement.innerHTML = codeElement.innerHTML.replace(/ @/g, ' <wbr />@');
});
</script>
<style>
body {
/* columns: 2; */
font-size: 12px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
h1 {
column-span: all;
text-align: center;
border: 1px solid black;
background-color: rgb(1, 36, 86);
padding: 1em;
color: rgb(224, 224, 224);
}
p {
margin: 0;
}
li {
list-style:none;
break-inside: avoid;
/* display: inline-block; */
}
ul {
display: block;
/* break-after: page; */
padding: 0;
}
pre, code {
display: inline-block;
font-family: "Fira Code", "Cascadia Code", "Consolas", monospace !important;
font-weight: 200;
}
pre {
padding: 5px !important;
}
@media print {
.toolbar {
display: none;
}
ul {
/* width: 50%; */
}
body {
/* column-count: 2;
column-gap: 3em; */
overflow: visible;
}
* {
overflow: visible !important;
}
}
</style>