Skip to content

Commit 8851d99

Browse files
Merge pull request #207428 from timwarner-msft/timwarner-mcmikey
Clean up PowerShell code
2 parents c59f987 + 55a5186 commit 8851d99

File tree

1 file changed

+57
-42
lines changed

1 file changed

+57
-42
lines changed

articles/governance/machine-configuration/machine-configuration-create-definition.md

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: How to create custom machine configuration policy definitions
33
description: Learn how to create a machine configuration policy.
4-
ms.date: 07/25/2022
4+
ms.date: 08/09/2022
55
ms.topic: how-to
66
ms.service: machine-configuration
77
ms.author: timwarner
@@ -115,31 +115,35 @@ Create a policy definition that audits using a custom
115115
configuration package, in a specified path:
116116

117117
```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
127129
```
128130

129131
Create a policy definition that deploys a configuration using a custom
130132
configuration package, in a specified path:
131133

132134
```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
143147
```
144148

145149
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
194198
list at the time of policy assignment.
195199

196200
```powershell
197-
# This DSC Resource text:
201+
# This DSC resource definition...
198202
Service 'UserSelectedNameExample'
199203
{
200204
Name = 'ParameterValue'
201205
Ensure = 'Present'
202206
State = 'Running'
203207
}`
204208
205-
# Would require the following hashtable:
206-
$PolicyParameterInfo = @(
209+
# ...can be converted to a hash table:
210+
$PolicyParameterInfo = @(
207211
@{
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
227242
```
228243

229244
### Publish the Azure Policy definition

0 commit comments

Comments
 (0)