-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo-partial.ps1
83 lines (57 loc) · 2.22 KB
/
demo-partial.ps1
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
#requires -version 5.0
#read more: https://msdn.microsoft.com/en-us/powershell/dsc/partialconfigs
#configure the LCM to accept partial configurations
Return "This is a demo file you silly human."
#region the configurations
psedit .\ServiceConfiguration.ps1
psedit .\FeaturesConfiguration.ps1
#endregion
#region the LCM config needed to enable partials
[DSCLocalConfigurationManager()]
configuration PartialConfig {
Param([string[]]$Computername)
Node $Computername {
PartialConfiguration ServiceConfiguration #<-- Name must match eventual configuration
{
Description = 'Configuration to configure services.'
RefreshMode = 'Push'
}
PartialConfiguration FeaturesConfiguration #<-- Name must match eventual configuration
{
Description = 'Configuration for Windows Features'
RefreshMode = 'Push'
}
Settings {
RebootNodeIfNeeded = $True
ConfigurationMode = 'ApplyAndAutoCorrect'
AllowModuleOverwrite = $True
}
} #node
} #config
PartialConfig -Computername SRV3 -OutputPath c:\DSC\PartialDemo
psedit C:\dsc\PartialDemo\SRV3.meta.mof
#endregion
#region deploy
#wipe current config
Remove-DscConfigurationDocument -Stage Current -CimSession SRV3
#current LCM
Get-DscLocalConfigurationManager -cimsession SRV3
#push new LCM config
Set-DscLocalConfigurationManager -Path C:\dsc\PartialDemo -Verbose
$lcm = Get-DscLocalConfigurationManager -cimsession SRV3
$lcm.PartialConfigurations
#publish partial configs with Publish-DSCConfiguration
Get-DscConfiguration -CimSession SRV3
#enable a feature to be removed
Add-WindowsFeature -Name Wins -ComputerName SRV3
Publish-DscConfiguration -Path C:\dsc\PartialDemo\FeaturesConfiguration -Verbose
Publish-DscConfiguration -Path C:\dsc\PartialDemo\ServiceConfiguration -Verbose
#endregion
#region apply with Start-DSCConfiguration and -UseExisting
Start-DscConfiguration -ComputerName SRV3 -Wait -UseExisting -Verbose
#wait for server to reboot if necessary
Get-windowsfeature -ComputerName SRV3 | where installed
Test-DscConfiguration -ComputerName SRV3 -Detailed
get-service remoteregistry,windefend,bits,spooler -com srv3 |
Select name,displayname,status,StartType,machinename | format-table
#endregion