|
1 | 1 | ---
|
2 | 2 | title: How to create custom machine configuration policy definitions
|
3 | 3 | description: Learn how to create a machine configuration policy.
|
4 |
| -ms.date: 07/25/2022 |
| 4 | +ms.date: 08/09/2022 |
5 | 5 | ms.topic: how-to
|
6 | 6 | ms.service: machine-configuration
|
7 | 7 | ms.author: timwarner
|
@@ -115,31 +115,35 @@ Create a policy definition that audits using a custom
|
115 | 115 | configuration package, in a specified path:
|
116 | 116 |
|
117 | 117 | ```powershell
|
118 |
| -New-GuestConfigurationPolicy ` |
119 |
| - -PolicyId 'My GUID' ` |
120 |
| - -ContentUri '<paste the ContentUri output from the Publish command>' ` |
121 |
| - -DisplayName 'My audit policy.' ` |
122 |
| - -Description 'Details about my policy.' ` |
123 |
| - -Path './policies' ` |
124 |
| - -Platform 'Windows' ` |
125 |
| - -PolicyVersion 1.0.0 ` |
126 |
| - -Verbose |
| 118 | +$PolicyConfig = @{ |
| 119 | + PolicyId = '_My GUID_' |
| 120 | + ContentUri = <_ContentUri output from the Publish command_> |
| 121 | + DisplayName = 'My audit policy' |
| 122 | + Description = 'My audit policy' |
| 123 | + Path = './policies' |
| 124 | + Platform = 'Windows' |
| 125 | + PolicyVersion = 1.0.0 |
| 126 | +} |
| 127 | +
|
| 128 | +New-GuestConfigurationPolicy @PolicyConfig |
127 | 129 | ```
|
128 | 130 |
|
129 | 131 | Create a policy definition that deploys a configuration using a custom
|
130 | 132 | configuration package, in a specified path:
|
131 | 133 |
|
132 | 134 | ```powershell
|
133 |
| -New-GuestConfigurationPolicy ` |
134 |
| - -PolicyId 'My GUID' ` |
135 |
| - -ContentUri '<paste the ContentUri output from the Publish command>' ` |
136 |
| - -DisplayName 'My audit policy.' ` |
137 |
| - -Description 'Details about my policy.' ` |
138 |
| - -Path './policies' ` |
139 |
| - -Platform 'Windows' ` |
140 |
| - -PolicyVersion 1.0.0 ` |
141 |
| - -Mode 'ApplyAndAutoCorrect' ` |
142 |
| - -Verbose |
| 135 | +$PolicyConfig2 = @{ |
| 136 | + PolicyId = '_My GUID_' |
| 137 | + ContentUri = <_ContentUri output from the Publish command_> |
| 138 | + DisplayName = 'My audit policy' |
| 139 | + Description = 'My audit policy' |
| 140 | + Path = './policies' |
| 141 | + Platform = 'Windows' |
| 142 | + PolicyVersion = 1.0.0 |
| 143 | + Mode = 'ApplyAndAutoCorrect' |
| 144 | +} |
| 145 | +
|
| 146 | +New-GuestConfigurationPolicy @PolicyConfig2 |
143 | 147 | ```
|
144 | 148 |
|
145 | 149 | The cmdlet output returns an object containing the definition display name and
|
@@ -194,36 +198,47 @@ The following example creates a policy definition to audit a service, where the
|
194 | 198 | list at the time of policy assignment.
|
195 | 199 |
|
196 | 200 | ```powershell
|
197 |
| -# This DSC Resource text: |
| 201 | +# This DSC resource definition... |
198 | 202 | Service 'UserSelectedNameExample'
|
199 | 203 | {
|
200 | 204 | Name = 'ParameterValue'
|
201 | 205 | Ensure = 'Present'
|
202 | 206 | State = 'Running'
|
203 | 207 | }`
|
204 | 208 |
|
205 |
| -# Would require the following hashtable: |
206 |
| -$PolicyParameterInfo = @( |
| 209 | +# ...can be converted to a hash table: |
| 210 | +$PolicyParameterInfo = @( |
207 | 211 | @{
|
208 |
| - Name = 'ServiceName' # Policy parameter name (mandatory) |
209 |
| - DisplayName = 'windows service name.' # Policy parameter display name (mandatory) |
210 |
| - Description = 'Name of the windows service to be audited.' # Policy parameter description (optional) |
211 |
| - ResourceType = 'Service' # DSC configuration resource type (mandatory) |
212 |
| - ResourceId = 'UserSelectedNameExample' # DSC configuration resource id (mandatory) |
213 |
| - ResourcePropertyName = 'Name' # DSC configuration resource property name (mandatory) |
214 |
| - DefaultValue = 'winrm' # Policy parameter default value (optional) |
215 |
| - AllowedValues = @('BDESVC','TermService','wuauserv','winrm') # Policy parameter allowed values (optional) |
216 |
| - } |
217 |
| -) |
218 |
| -
|
219 |
| -New-GuestConfigurationPolicy ` |
220 |
| - -PolicyId 'My GUID' ` |
221 |
| - -ContentUri '<paste the ContentUri output from the Publish command>' ` |
222 |
| - -DisplayName 'Audit Windows Service.' ` |
223 |
| - -Description 'Audit if a Windows Service isn't enabled on Windows machine.' ` |
224 |
| - -Path '.\policies' ` |
225 |
| - -Parameter $PolicyParameterInfo ` |
226 |
| - -PolicyVersion 1.0.0 |
| 212 | + # Policy parameter name (mandatory) |
| 213 | + Name = 'ServiceName' |
| 214 | + # Policy parameter display name (mandatory) |
| 215 | + DisplayName = 'windows service name.' |
| 216 | + # Policy parameter description (optional) |
| 217 | + Description = 'Name of the windows service to be audited.' |
| 218 | + # DSC configuration resource type (mandatory) |
| 219 | + ResourceType = 'Service' |
| 220 | + # DSC configuration resource id (mandatory) |
| 221 | + ResourceId = 'UserSelectedNameExample' |
| 222 | + # DSC configuration resource property name (mandatory) |
| 223 | + ResourcePropertyName = 'Name' |
| 224 | + # Policy parameter default value (optional) |
| 225 | + DefaultValue = 'winrm' |
| 226 | + # Policy parameter allowed values (optional) |
| 227 | + AllowedValues = @('BDESVC','TermService','wuauserv','winrm') |
| 228 | + }) |
| 229 | +
|
| 230 | +# ...and then passed into the `New-GuestConfigurationPolicy` cmdlet |
| 231 | +$PolicyParam = @{ |
| 232 | + PolicyId = 'My GUID' |
| 233 | + ContentUri = '<ContentUri output from the Publish command>' |
| 234 | + DisplayName = 'Audit Windows Service.' |
| 235 | + Description = "Audit if a Windows Service isn't enabled on Windows machine." |
| 236 | + Path = '.\policies' |
| 237 | + Parameter = $PolicyParameterInfo |
| 238 | + PolicyVersion = 1.0.0 |
| 239 | +} |
| 240 | +
|
| 241 | +New-GuestConfigurationPolicy @PolicyParam |
227 | 242 | ```
|
228 | 243 |
|
229 | 244 | ### Publish the Azure Policy definition
|
|
0 commit comments