Skip to content

Instantly share code, notes, and snippets.

@bobalob
Last active December 7, 2016 12:15
Show Gist options
  • Save bobalob/b43ef01ee003f50ec90d61ae15e15338 to your computer and use it in GitHub Desktop.
Save bobalob/b43ef01ee003f50ec90d61ae15e15338 to your computer and use it in GitHub Desktop.
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