@@ -165,6 +165,28 @@ $roleCapabilityOptions = @{
165
165
166
166
New-PSRoleCapabilityFile @roleCapabilityOptions
167
167
168
+ # Merging role capabilities
169
+
170
+ # Cmdlets/functions in one capability
171
+ $capA = @ {VisibleCmdlets = ' Get-Process' }
172
+ $capB = @ {}
173
+ $merge = @ {VisibleCmdlets = ' Get-Process' }
174
+
175
+ # Cmdlets/functions in muliple capabilities
176
+ $capA = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Name' }}
177
+ $capB = @ {VisibleCmdlets = ' Get-Process' }
178
+ $merge = @ {VisibleCmdlets = ' Get-Process' }
179
+
180
+ $capA = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Name' }}
181
+ $capB = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Id' }}
182
+ $merge = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Name' }, @ {Name = ' Id' }}
183
+
184
+ # Validation in multiple roles
185
+ $capA = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Name' ; ValidateSet = ' A' , ' B' }}
186
+ $capB = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Name' ; ValidateSet = ' C' }}
187
+ $merge = @ {VisibleCmdlets = ' Get-Process' ; Parameters = @ {Name = ' Name' ; ValidateSet = ' A' , ' B'' C' }}
188
+
189
+
168
190
# Session configurations
169
191
170
192
# Again, it is easier to edit the file manually
@@ -198,4 +220,174 @@ Register-PSSessionConfiguration -Name WithUserDrive -Path .\SessionConfig.pssc
198
220
$session = New-PSSession - ComputerName localhost - ConfigurationName WithUserDrive
199
221
' it just works' | Set-Content .\JeaTest.file
200
222
Copy-Item - ToSession $session - Path .\JeaTest.file - Destination user:\JeaTest.file
201
- Copy-Item - FromSession $session - Path user:\JeaTest.file - Destination .\JeaTestFromConstrainedSession.file
223
+ Copy-Item - FromSession $session - Path user:\JeaTest.file - Destination .\JeaTestFromConstrainedSession.file
224
+
225
+ # Register an individual session configuration
226
+
227
+ $roleCapabilitiesFolder = New-Item - Path (Join-Path ($env: PSModulePath -split ' ;' )[1 ] ' JeaCapabilities\RoleCapabilities' ) - ItemType Directory - Force
228
+ $roleCapabilityOptions = @ {
229
+ Path = Join-Path $roleCapabilitiesFolder ' FirstLevelUserSupport.psrc'
230
+ Description = ' Provides first level support access to change user passwords'
231
+ VisibleCmdlets = @ (
232
+ @ {
233
+ Name = ' Get-Service'
234
+ Parameters = @ {
235
+ Name = ' Name'
236
+ ValidateSet = ' Spooler'
237
+ }
238
+ }
239
+ @ {
240
+ Name = ' Add-NTFSAccess'
241
+ Parameters = @ {
242
+ Name = ' Path'
243
+ ValidatePattern = ' \\\\namespace\\groupshare\\Group.*'
244
+ },
245
+ @ { Name = ' Account' },
246
+ @ {Name = ' AccessRights' },
247
+ @ {Name = ' AccessType' },
248
+ @ {Name = ' InheritanceFlags' },
249
+ @ {Name = ' PropagationFlags' }
250
+ }
251
+ ' Read-Host'
252
+ )
253
+ VisibleFunctions = ' Get-DepartmentAdUser' , ' Get-DepartmentAdGroupMember' , ' Add-DepartmentAdGroupMember'
254
+ FunctionDefinitions = @ {
255
+ Name = ' Get-DepartmentAdUser'
256
+ ScriptBlock = {
257
+ [CmdletBinding ()]
258
+ param
259
+ (
260
+ [Parameter (Mandatory )]
261
+ [string ]
262
+ $DepartmentName ,
263
+
264
+ [Parameter (Mandatory )]
265
+ [string ]
266
+ $UserName
267
+ )
268
+
269
+ Get-ADUser - SearchBase " OU=Users,OU=$DepartmentName ,DC=contoso,DC=com" - SearchScope Subtree - Identity $UserName
270
+ }
271
+ },
272
+ @ {
273
+ Name = ' Get-DepartmentAdGroupMember'
274
+ ScriptBlock = {
275
+ [CmdletBinding ()]
276
+ param
277
+ (
278
+ [Parameter (Mandatory )]
279
+ [string ]
280
+ $DepartmentName ,
281
+
282
+ [Parameter (Mandatory )]
283
+ [string ]
284
+ $GroupName
285
+ )
286
+
287
+ Get-AdGroupMember - Identity " CN=$GroupName ,OU=$DepartmentName ,DC=contoso,DC=com"
288
+ }
289
+ },
290
+ @ {
291
+ Name = ' Add-DepartmentAdGroupMember'
292
+ ScriptBlock = {
293
+ [CmdletBinding ()]
294
+ param
295
+ (
296
+ [Parameter (Mandatory )]
297
+ [string ]
298
+ $DepartmentName ,
299
+
300
+ [Parameter (Mandatory )]
301
+ [string ]
302
+ $GroupName ,
303
+
304
+ [Parameter (Mandatory )]
305
+ [string []]
306
+ $MemberName
307
+ )
308
+
309
+ Add-AdGroupMember - Identity " CN=$GroupName ,OU=$DepartmentName ,DC=contoso,DC=com" - Members $MemberName
310
+ }
311
+ }
312
+ }
313
+
314
+ New-PSRoleCapabilityFile @roleCapabilityOptions
315
+
316
+ # Session configurations
317
+
318
+ # Again, it is easier to edit the file manually
319
+ $sessionConfigurationOptions = @ {
320
+ Path = ' .\SessionConfig.pssc'
321
+ SessionType = ' RestrictedRemoteServer'
322
+ TranscriptDirectory = ' C:\Transcripts'
323
+ RunAsVirtualAccount = $true
324
+ LanguageMode = ' ConstrainedLanguage'
325
+ RoleDefinitions = @ {
326
+ ' contoso\FirstLevelSupport' = @ {RoleCapabilities = ' FirstLevelUserSupport' }
327
+ }
328
+ }
329
+
330
+ New-PSSessionConfigurationFile @sessionConfigurationOptions
331
+
332
+ Register-PSSessionConfiguration - Path .\SessionConfig.pssc - Name SupportSession
333
+
334
+ # Distibuted session configuration
335
+ $sessions = New-PSSession - ComputerName (1 .. 10 | % { " Node$_ " })
336
+ $path = (Join-Path ($env: PSModulePath -split ' ;' )[1 ] ' JeaCapabilities' )
337
+ foreach ($session in $sessions )
338
+ {
339
+ Copy-Item - Path $path - Destination $path - Recurse - ToSession $session - Force
340
+ }
341
+
342
+ Invoke-Command - Session $sessions - ScriptBlock {
343
+ $sessionConfigurationOptions = @ {
344
+ Path = ' .\SessionConfig.pssc'
345
+ SessionType = ' RestrictedRemoteServer'
346
+ TranscriptDirectory = ' C:\Transcripts'
347
+ RunAsVirtualAccount = $true
348
+ LanguageMode = ' ConstrainedLanguage'
349
+ RoleDefinitions = @ {
350
+ ' contoso\FirstLevelSupport' = @ {RoleCapabilities = ' FirstLevelUserSupport' }
351
+ }
352
+ }
353
+
354
+ New-PSSessionConfigurationFile @sessionConfigurationOptions
355
+
356
+ Register-PSSessionConfiguration - Path .\SessionConfig.pssc - Name SupportSession - Force
357
+ }
358
+
359
+ # Deployment with DSC
360
+ configuration JeaEndpointConfiguration
361
+ {
362
+ param
363
+ (
364
+ [string []]$ComputerName
365
+ )
366
+ Import-DscResource - ModuleName JustEnoughAdministration
367
+
368
+ node $ComputerName
369
+ {
370
+
371
+ File RoleCapabilities
372
+ {
373
+ SourcePath = ' \\contoso.com\ReadOnlyShare\JeaCapabilities'
374
+ DestinationPath = (Join-Path ($env: PSModulePath -split ' ;' )[1 ] ' JeaCapabilities' )
375
+ Ensure = ' Present'
376
+ Recurse = $true
377
+ Force = $true
378
+ }
379
+
380
+ JeaEndpoint EndpointConfiguration
381
+ {
382
+ EndpointName = ' SupportSession'
383
+ RoleDefinitions = ' @{"contoso\FirstLevelSupport" = @{RoleCapabilities = "FirstLevelUserSupport"}}'
384
+ DependsOn = ' [File]RoleCapabilities'
385
+ Ensure = ' Present'
386
+ TranscriptDirectory = ' C:\Transcripts'
387
+ }
388
+ }
389
+ }
390
+
391
+ # Create MOF files
392
+ JeaEndpointConfiguration - ComputerName (1 .. 10 | % { " Node$_ " })
393
+ Start-DscConfiguration - Path .\JeaEndpointConfiguration - Wait - Verbose
0 commit comments