Skip to content

Commit f0486bd

Browse files
Merge pull request #89 from PowerShell/dev
Release of version 3.8.0.0 of xPSDesiredStateConfiguration
2 parents 3742e73 + ae79c89 commit f0486bd

9 files changed

Lines changed: 355 additions & 102 deletions

File tree

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<#
2+
.Synopsis
3+
Package DSC modules and mof configuration document and publish them on enterprise DSC pull server in the required format
4+
.DESCRIPTION
5+
Uses Publish-DSCModulesAndMofs cmdlet to package DSC modules into zip files with the version info. If
6+
Publishes the zip modules on "$env:ProgramFiles\WindowsPowerShell\DscService\Modules"
7+
Publishes all mof configuration documents that present in $Source folder on "$env:ProgramFiles\WindowsPowerShell\DscService\Configuration"
8+
Use $Force to overwrite the version of the module that exists in powershell module path with the version from $source folder
9+
Use $ModuleNameList to specify the names of the modules to be published if the modules do not exist in $Source folder
10+
11+
.EXAMPLE
12+
$moduleList = @("xWebAdministration", "xPhp")
13+
Publish-DSCModuleAndMof -Source C:\LocalDepot -ModuleNameList $moduleList
14+
.EXAMPLE
15+
Publish-DSCModuleAndMof -Source C:\LocalDepot -Force
16+
17+
#>
18+
19+
# Tools to use to package DSC modules and mof configuration document and publish them on enterprise DSC pull server in the required format
20+
21+
function Publish-DSCModuleAndMof
22+
{
23+
param(
24+
25+
[Parameter(Mandatory=$True)]
26+
[string]$Source = $pwd, # The folder that contains the configuration mof documents and modules to be published on pull server. Everything in this folder will be packaged and published.
27+
[switch]$Force, #switch to overwrite the module in PSModulePath with the version provided in $Sources
28+
[string[]]$ModuleNameList # Package and publish the modules listed in $ModuleNameList based on powershell module path content
29+
30+
)
31+
32+
#Create a working directory
33+
$tempFolder = "$pwd\temp"
34+
New-Item -Path $tempFolder -ItemType Directory -Force -ErrorAction SilentlyContinue
35+
36+
#Copy the mof documents from the $Source to working dir
37+
Copy-Item -Path "$Source\*.mof" -Destination $tempFolder -Force -Verbose
38+
39+
#Start Deployment!
40+
Write-Host "Start deployment"
41+
CreateZipFromPSModulePath -listModuleNames $ModuleNameList -destination $tempFolder
42+
CreateZipFromSource -source $Source -destination $tempFolder
43+
# Generate the checkSum file for all the zip and mof files.
44+
New-DSCCheckSum $tempFolder -Force
45+
# Publish mof and modules to pull server repositories
46+
PublishModulesAndChecksum -source $tempFolder
47+
PublishMofDocuments -source $tempFolder
48+
#Deployment is complete!
49+
Remove-Item -Path $tempFolder -Recurse -Force -ErrorAction SilentlyContinue
50+
Write-Host "End deployment"
51+
52+
}
53+
54+
#Package the modules using powershell module path
55+
function CreateZipFromPSModulePath
56+
{
57+
param($listModuleNames, $destination)
58+
# Move all required modules from powershell module path to a temp folder and package them
59+
if(($listModuleNames -eq $null) -or ($listModuleNames.Count -eq 0))
60+
{
61+
Write-Host "No additional modules are specified to be packaged."
62+
}
63+
foreach ($module in $listModuleNames)
64+
{
65+
$allVersions = Get-Module -Name $module -ListAvailable -Verbose
66+
#package all versions of the module
67+
foreach($moduleVersion in $allVersions)
68+
{
69+
$name = $moduleVersion.Name
70+
$source = "$destination\$name"
71+
#Create package zip
72+
$path = $moduleVersion.ModuleBase
73+
Compress-Archive -Path "$path\*" -DestinationPath "$source.zip" -Verbose -Force
74+
$version = $moduleVersion.Version.ToString()
75+
$newName = "$destination\$name" + "_" + "$version" + ".zip"
76+
# Rename the module folder to contain the version info.
77+
if(Test-Path($newName))
78+
{
79+
Remove-Item $newName -Recurse -Force
80+
}
81+
Rename-Item -Path "$source.zip" -NewName $newName -Force
82+
83+
}
84+
}
85+
86+
}
87+
#Function to package modules using a given folder after installing to ps module path.
88+
function CreateZipFromSource
89+
{
90+
param($source, $destination)
91+
# for each module under $Source folder create a zip package that has the same name as the folder.
92+
$allModulesInSource = Get-ChildItem $source -Directory
93+
$modules = @()
94+
95+
foreach ($item in $allModulesInSource)
96+
{
97+
$name = $item.Name
98+
$alreadyExists = Get-Module -Name $name -ListAvailable -Verbose
99+
if(($alreadyExists -eq $null) -or ($Force))
100+
{
101+
#install the modules into powershell module path and overwrite the content
102+
Copy-Item $item.FullName -Recurse -Force -Destination "$env:ProgramFiles\WindowsPowerShell\Modules" -Verbose
103+
}
104+
else
105+
{
106+
Write-Host "Skipping module overwrite. Module with the name $name already exists. Please specify -Force to overwrite the module with the local version of the module located in $source or list names of the modules in ModuleNameList parameter to be packaged from powershell module pat instead and remove them from $source folder" -Fore Red
107+
}
108+
$modules+= @("$name")
109+
}
110+
#Package the module in $destination
111+
CreateZipFromPSModulePath -listModuleNames $modules -destination $destination
112+
}
113+
114+
115+
# Deploy modules to the pullsever repository.
116+
function PublishModulesAndChecksum
117+
{
118+
param($source)
119+
# Check if the current machine is a server sku.
120+
$moduleRepository = "$env:ProgramFiles\WindowsPowerShell\DscService\Modules"
121+
if( (Get-Module ServerManager -ListAvailable) -and (Test-Path ($moduleRepository)))
122+
{
123+
Copy "$source\*.zip*" $moduleRepository -Force -Verbose
124+
}
125+
else
126+
{
127+
Write-Host "Copying modules to pullserver module repository skipped because the machine is not a server sku or Pull server endpoint is not deployed." -Fore Yellow
128+
}
129+
130+
}
131+
132+
# function deploy configuratoin and thier checksum.
133+
function PublishMofDocuments
134+
{
135+
param($source)
136+
# Check if the current machine is a server sku.
137+
$mofRepository = "$env:ProgramFiles\WindowsPowerShell\DscService\Configuration"
138+
if( (Get-Module ServerManager -ListAvailable) -and (Test-Path ($mofRepository)) )
139+
{
140+
Copy-Item "$source\*.mof*" $mofRepository -Force -Verbose
141+
}
142+
else
143+
{
144+
Write-Host "Copying configuration(s) to pullserver configuration repository skipped because the machine is not a server sku or Pull server endpoint is not deployed." -Fore Yellow
145+
}
146+
}
147+
Export-ModuleMember -Function Publish-DSCModuleAndMof

DSCPullServerSetup/README.md

334 Bytes

DSCPullServer contains utilities to automate DSC module and configuration document packaging and delpoyment on enterprise pull server , documentation and examples

DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.Schema.mof

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class MSFT_xDSCWebService : OMI_BaseResource
99
[write,ValueMap{"Started","Stopped"},Values{"Started", "Stopped"}] string State;
1010
[write] string ModulePath;
1111
[write] string ConfigurationPath;
12-
[write] boolean IsComplianceServer;
1312
[read] string DSCServerUrl;
1413
[write] string RegistrationKeyPath;
1514
[write] boolean AcceptSelfSignedCertificates;

DSCResources/MSFT_xDSCWebService/MSFT_xDSCWebService.psm1

Lines changed: 51 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function Set-TargetResource
9494
[string]$EndpointName,
9595

9696
# Port number of the DSC Pull Server IIS Endpoint
97-
[Uint32]$Port = $( if ($IsComplianceServer) { 7070 } else { 8080 } ),
97+
[Uint32]$Port = 8080,
9898

9999
# Physical path for the IIS Endpoint on the machine (usually under inetpub)
100100
[string]$PhysicalPath = "$env:SystemDrive\inetpub\$EndpointName",
@@ -116,14 +116,11 @@ function Set-TargetResource
116116
# Location on the disk where the Configuration is stored
117117
[string]$ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration",
118118

119-
# Is the endpoint for a DSC Compliance Server
120-
[boolean]$IsComplianceServer,
121-
122119
# Location on the disk where the RegistrationKeys file is stored
123120
[string]$RegistrationKeyPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService",
124121

125122
# Add the IISSelfSignedCertModule native module to prevent self-signed certs being rejected.
126-
[boolean]$AcceptSelfSignedCertificates
123+
[boolean]$AcceptSelfSignedCertificates = $true
127124
)
128125

129126
# Initialize with default values
@@ -150,41 +147,18 @@ function Set-TargetResource
150147
$IsBlue = $true;
151148
}
152149

150+
$isDownlevelOfBlue = $false;
151+
if($os.Major -eq 6 -and $os.Minor -lt 3)
152+
{
153+
$isDownlevelOfBlue= $true;
154+
}
155+
153156
# Use Pull Server values for defaults
154157
$webConfigFileName = "$pathPullServer\PSDSCPullServer.config"
155158
$svcFileName = "$pathPullServer\PSDSCPullServer.svc"
156159
$pswsMofFileName = "$pathPullServer\PSDSCPullServer.mof"
157160
$pswsDispatchFileName = "$pathPullServer\PSDSCPullServer.xml"
158161

159-
# Update only if Compliance Server install is requested
160-
if ($IsComplianceServer)
161-
{
162-
$webConfigFileName = "$pathPullServer\PSDSCComplianceServer.config"
163-
$svcFileName = "$pathPullServer\PSDSCComplianceServer.svc"
164-
$pswsMofFileName = "$pathPullServer\PSDSCComplianceServer.mof"
165-
$pswsDispatchFileName = "$pathPullServer\PSDSCComplianceServer.xml"
166-
}
167-
168-
# check for the existance of Windows authentication, this is needed for the Compliance Server
169-
if(($Ensure -eq "Present"))
170-
{
171-
Write-Verbose "Check IIS Windows Authentication"
172-
# only important if Present, Get-WindowsFeature works under 2008 R2 and newer
173-
if ((Get-WindowsFeature -name Web-Windows-Auth | Where Installed).count -eq 0)
174-
{
175-
# enable the feature
176-
# Checking for Windows Server 2008 R2:
177-
if([Environment]::OSVersion.Version.ToString().StartsWith("6.1."))
178-
{
179-
Add-WindowsFeature -Name Web-Windows-Auth
180-
}
181-
else
182-
{
183-
Install-WindowsFeature -Name Web-Windows-Auth
184-
}
185-
}
186-
}
187-
188162
# ============ Absent block to remove existing site =========
189163
if(($Ensure -eq "Absent"))
190164
{
@@ -200,7 +174,6 @@ function Set-TargetResource
200174
return
201175
}
202176
# ===========================================================
203-
204177

205178
Write-Verbose "Create the IIS endpoint"
206179
PSWSIISEndpoint\New-PSWSEndpoint -site $EndpointName `
@@ -223,68 +196,67 @@ function Set-TargetResource
223196
Update-LocationTagInApplicationHostConfigForAuthentication -WebSite $EndpointName -Authentication "basic"
224197
Update-LocationTagInApplicationHostConfigForAuthentication -WebSite $EndpointName -Authentication "windows"
225198

226-
227199
if ($IsBlue)
228200
{
229201
Write-Verbose "Set values into the web.config that define the repository for BLUE OS"
230-
#PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbprovider" -value $eseprovider
231-
#PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbconnectionstr"-value $esedatabase
232-
#ESE database is not present in current build
233-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbprovider" -value $jet4provider
234-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbconnectionstr" -value $jet4database
202+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbprovider" -value $eseprovider
203+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbconnectionstr"-value $esedatabase
235204
Set-BindingRedirectSettingInWebConfig -path $PhysicalPath
236205
}
237206
else
238207
{
239-
Write-Verbose "Set values into the web.config that define the repository for non-BLUE Downlevel OS"
240-
$repository = Join-Path "$rootDataPath" "Devices.mdb"
241-
Copy-Item "$pathPullServer\Devices.mdb" $repository -Force
208+
if($isDownlevelOfBlue)
209+
{
210+
Write-Verbose "Set values into the web.config that define the repository for non-BLUE Downlevel OS"
211+
$repository = Join-Path "$rootDataPath" "Devices.mdb"
212+
Copy-Item "$pathPullServer\Devices.mdb" $repository -Force
242213

243-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbprovider" -value $jet4provider
244-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbconnectionstr" -value $jet4database
245-
}
214+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbprovider" -value $jet4provider
215+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbconnectionstr" -value $jet4database
216+
}
217+
else
218+
{
219+
Write-Verbose "Set values into the web.config that define the repository later than BLUE OS"
220+
Write-Verbose "Only ESENT is supported on Windows Server 2016"
246221

247-
if ($IsComplianceServer)
248-
{
249-
Write-Verbose "Compliance Server: Set values into the web.config that indicate this is the admin endpoint"
250-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "AdminEndPoint" -value "true"
222+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbprovider" -value $eseprovider
223+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "dbconnectionstr"-value $esedatabase
224+
}
251225
}
252-
else
253-
{
254-
Write-Verbose "Pull Server: Set values into the web.config that indicate the location of repository, configuration, modules"
255226

256-
# Create the application data directory calculated above
257-
$null = New-Item -path $rootDataPath -itemType "directory" -Force
258-
259-
$repository = Join-Path $rootDataPath "Devices.mdb"
260-
Copy-Item "$pathPullServer\Devices.mdb" $repository -Force
227+
Write-Verbose "Pull Server: Set values into the web.config that indicate the location of repository, configuration, modules"
261228

262-
$null = New-Item -path "$ConfigurationPath" -itemType "directory" -Force
229+
# Create the application data directory calculated above
230+
$null = New-Item -path $rootDataPath -itemType "directory" -Force
263231

264-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "ConfigurationPath" -value $ConfigurationPath
232+
$repository = Join-Path $rootDataPath "Devices.mdb"
233+
Copy-Item "$pathPullServer\Devices.mdb" $repository -Force
265234

266-
$null = New-Item -path "$ModulePath" -itemType "directory" -Force
235+
$null = New-Item -path "$ConfigurationPath" -itemType "directory" -Force
267236

268-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "ModulePath" -value $ModulePath
237+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "ConfigurationPath" -value $ConfigurationPath
269238

270-
$null = New-Item -path "$RegistrationKeyPath" -itemType "directory" -Force
239+
$null = New-Item -path "$ModulePath" -itemType "directory" -Force
271240

272-
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "RegistrationKeyPath" -value $RegistrationKeyPath
241+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "ModulePath" -value $ModulePath
273242

274-
if($AcceptSelfSignedCertificates)
275-
{
276-
Copy-Item "$pathPullServer\IISSelfSignedCertModule.dll" $env:windir\System32\inetsrv -Force
277-
Copy-Item "$env:windir\SysWOW64\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PullServer\IISSelfSignedCertModule.dll" $env:windir\SysWOW64\inetsrv -Force
243+
$null = New-Item -path "$RegistrationKeyPath" -itemType "directory" -Force
278244

279-
& $script:appCmd install module /name:"IISSelfSignedCertModule(32bit)" /image:$env:windir\SysWOW64\inetsrv\IISSelfSignedCertModule.dll /add:false /lock:false
280-
& $script:appCmd add module /name:"IISSelfSignedCertModule(32bit)" /app.name:"PSDSCPullServer/"
281-
}
282-
else
245+
PSWSIISEndpoint\Set-AppSettingsInWebconfig -path $PhysicalPath -key "RegistrationKeyPath" -value $RegistrationKeyPath
246+
247+
if($AcceptSelfSignedCertificates)
248+
{
249+
Copy-Item "$pathPullServer\IISSelfSignedCertModule.dll" $env:windir\System32\inetsrv -Force
250+
Copy-Item "$env:windir\SysWOW64\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PullServer\IISSelfSignedCertModule.dll" $env:windir\SysWOW64\inetsrv -Force
251+
252+
& $script:appCmd install module /name:"IISSelfSignedCertModule(32bit)" /image:$env:windir\SysWOW64\inetsrv\IISSelfSignedCertModule.dll /add:false /lock:false
253+
& $script:appCmd add module /name:"IISSelfSignedCertModule(32bit)" /app.name:"PSDSCPullServer/"
254+
}
255+
else
256+
{
257+
if($AcceptSelfSignedCertificates -and ($AcceptSelfSignedCertificates -eq $false))
283258
{
284-
if($AcceptSelfSignedCertificates -and ($AcceptSelfSignedCertificates -eq $false))
285-
{
286-
& $script:appCmd delete module /name:"IISSelfSignedCertModule(32bit)" /app.name:"PSDSCPullServer/"
287-
}
259+
& $script:appCmd delete module /name:"IISSelfSignedCertModule(32bit)" /app.name:"PSDSCPullServer/"
288260
}
289261
}
290262
}
@@ -301,7 +273,7 @@ function Test-TargetResource
301273
[string]$EndpointName,
302274

303275
# Port number of the DSC Pull Server IIS Endpoint
304-
[Uint32]$Port = $( if ($IsComplianceServer) { 7070 } else { 8080 } ),
276+
[Uint32]$Port = 8080,
305277

306278
# Physical path for the IIS Endpoint on the machine (usually under inetpub)
307279
[string]$PhysicalPath = "$env:SystemDrive\inetpub\$EndpointName",
@@ -323,13 +295,10 @@ function Test-TargetResource
323295
# Location on the disk where the Configuration is stored
324296
[string]$ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration",
325297

326-
# Is the endpoint for a DSC Compliance Server
327-
[boolean]$IsComplianceServer,
328-
329298
# Location on the disk where the RegistrationKeys file is stored
330299
[string]$RegistrationKeyPath,
331300

332-
# Are self-signed certs being accepted for client auth.
301+
# Are self-signed certs being accepted for client auth.
333302
[boolean]$AcceptSelfSignedCertificates
334303
)
335304

@@ -361,19 +330,6 @@ function Test-TargetResource
361330
}
362331
# the other case is: Ensure and exist, we continue with more checks
363332

364-
# check for the existance of Windows authentication, this is needed for the Compliance Server
365-
if(($Ensure -eq "Present"))
366-
{
367-
Write-Verbose "Check IIS Windows Authentication"
368-
# only important if Present, Get-WindowsFeature works under 2008 R2 and newer
369-
if ((Get-WindowsFeature -name Web-Windows-Auth | Where Installed).count -eq 0)
370-
{
371-
$DesiredConfigurationMatch = $false
372-
Write-Verbose "Required Windows authentication is not installed, does not match the desired state."
373-
break
374-
}
375-
}
376-
377333
Write-Verbose "Check Port"
378334
$actualPort = $website.bindings.Collection[0].bindingInformation.Split(":")[1]
379335
if ($Port -ne $actualPort)

0 commit comments

Comments
 (0)