Last active
December 7, 2016 12:15
-
-
Save bobalob/b43ef01ee003f50ec90d61ae15e15338 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | |
Install-Module xPSDesiredStateConfiguration -Force | |
configuration CreatePullServer | |
{ | |
param | |
( | |
[Parameter(Mandatory=$true)][string[]]$ComputerName, | |
[Parameter(Mandatory=$true)][string]$CertThumbprint | |
) | |
Import-DscResource -ModuleName 'PSDesiredStateConfiguration' | |
Import-DSCResource -ModuleName 'xPSDesiredStateConfiguration' | |
Node $ComputerName | |
{ | |
WindowsFeature DSCServiceFeature | |
{ | |
Ensure = "Present" | |
Name = "DSC-Service" | |
} | |
xDscWebService PSDSCPullServer | |
{ | |
Ensure = "Present" | |
EndpointName = "PSDSCPullServer" | |
Port = 8080 | |
PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCPullServer" | |
CertificateThumbPrint = $CertThumbprint | |
ModulePath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Modules" | |
ConfigurationPath = "$env:PROGRAMFILES\WindowsPowerShell\DscService\Configuration" | |
State = "Started" | |
DependsOn = "[WindowsFeature]DSCServiceFeature" | |
UseSecurityBestPractices = $True | |
} | |
xDscWebService PSDSCComplianceServer | |
{ | |
Ensure = "Present" | |
EndpointName = "PSDSCComplianceServer" | |
Port = 9080 | |
PhysicalPath = "$env:SystemDrive\inetpub\wwwroot\PSDSCComplianceServer" | |
CertificateThumbPrint = $CertThumbprint | |
State = "Started" | |
DependsOn = ("[WindowsFeature]DSCServiceFeature","[xDSCWebService]PSDSCPullServer") | |
UseSecurityBestPractices = $True | |
} | |
} | |
} | |
if ($ENV:USERDNSNAME) { | |
$ComputerName = "$ENV:COMPUTERNAME.$ENV:USERDNSNAME".ToLower() | |
} else { | |
$ComputerName = "$ENV:COMPUTERNAME".ToLower() | |
} | |
$Cert = New-SelfSignedCertificate -DnsName $ComputerName ` | |
-CertStoreLocation "cert:\LocalMachine\My" ` | |
-FriendlyName "PSDSCPullServerCert" | |
CreatePullServer -ComputerName $ComputerName ` | |
-CertThumbprint $Cert.Thumbprint ` | |
-OutputPath C:\DSC\HTTPS | |
Start-DscConfiguration -Path C:\DSC\HTTPS ` | |
-ComputerName $ComputerName -Verbose -Wait -force | |
Write-Host "New Self-Signed Certificate Thumbprint for this server is $($Cert.Thumbprint)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment