Skip to content

Instantly share code, notes, and snippets.

@bobalob
Created December 2, 2016 18:34
Show Gist options
  • Save bobalob/d8679ab5c167707ecb82e8b4fd1ca19d to your computer and use it in GitHub Desktop.
Save bobalob/d8679ab5c167707ecb82e8b4fd1ca19d to your computer and use it in GitHub Desktop.
Param(
[Parameter(Mandatory=$true)][ValidateNotNullorEmpty()]$ComputerName,
$publicKeysLocation = "C:\DSC\publicKeys\",
$configDataLocation = "C:\DSC\ConfigData\"
)
$DSCCert = Invoke-Command -ComputerName $ComputerName -ScriptBlock {
dir cert:\LocalMachine\My | ? { $_.EnhancedKeyUsageList -match "Document Encryption"}
}
if ($DSCCert) {
if (!(Test-Path $publicKeysLocation)) {mkdir $publicKeysLocation}
if (!(Test-Path $configDataLocation)) {mkdir $configDataLocation}
$OutFile = "$($configDataLocation)\$($ComputerName)-ConfigData.psd1"
$NodeConf = $Null
$certLoc = "$($publicKeysLocation)\$($ComputerName).cer"
$export = Export-Certificate -Type CERT -FilePath $certLoc -Cert $DSCCert
$configData = "@{" + "`n"
$configData += " AllNodes = @(" + "`n"
$configData += " @{" + "`n"
$configData += " Thumbprint=`"$($DSCCert.Thumbprint)`"" + "`n"
$configData += " CertificateFile=`"$($certLoc)`"" + "`n"
$configData += " NodeName=`"$($ComputerName)`"" + "`n"
$configData += " PSDscAllowDomainUser = `$True" + "`n"
$configData += " }" + "`n"
$configData += " )" + "`n"
$configData += "}"
$configData | Out-File $OutFile
Write-Host $configData
Write-Host "Written to $($OutFile)" -ForegroundColor Yellow
} else {
Write-Warning "The remote computer $($ComputerName) does not have a valid certificate for DSC Encryption"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment