Skip to content

Instantly share code, notes, and snippets.

@cyberautomate
Created December 18, 2021 00:32
Show Gist options
  • Select an option

  • Save cyberautomate/625dc9c7da58ab525e6292774bd977f7 to your computer and use it in GitHub Desktop.

Select an option

Save cyberautomate/625dc9c7da58ab525e6292774bd977f7 to your computer and use it in GitHub Desktop.
[DSCLocalConfigurationManager()]
configuration LCMConfigNames
{
param
(
[Parameter(Mandatory= $true)]
[string[]]$ComputerName,
[Parameter(Mandatory= $true)]
[string]$regKey,
[Parameter(Mandatory= $true)]
[string]$pullThumbprint
)
Node $ComputerName
{
Settings
{
RefreshMode = 'Pull'
RefreshFrequencyMins = 30
RebootNodeIfNeeded = $true
AllowModuleOverwrite = $true
}
ConfigurationRepositoryWeb DSCHTTPS
{
ServerURL = 'https://pull.dsc.local/PSDSCPullServer.svc'
RegistrationKey = $regKey
ConfigurationNames = @('localhost')
CertificateID = $pullThumbprint
AllowUnsecureConnection = $false
}
ReportServerWeb DSCReports
{
ServerURL = 'https://pull.dsc.local/PSDSCPullServer.svc'
}
}
}
$Computers = 'SVR19-3' # Get-content C:\dsc\computers.txt
# Get the cert thumbprint
$pullThumbprint = Get-ChildItem Cert:\LocalMachine\My |
Where-Object {$_.FriendlyName -eq 'DSCPullServerCert'} |
Select-Object -ExpandProperty Thumbprint
# Get the registration key
$regkey = Get-content "$env:ProgramFiles\WindowsPowerShell\DscService\RegistrationKeys.txt"
# Loop through the list of computers and set the LCM
Foreach ($computer in $computers){
$session = New-CimSession -ComputerName $computer
LCMConfigNames -ComputerName $computer -pullThumbprint $pullThumbprint -regKey $regkey -OutputPath C:\DSC\Node_Configs
Set-DscLocalConfigurationManager -CimSession $session -Path C:\DSC\Node_Configs -Verbose
}
# Check the progress on the Endpoint
$session = New-CimSession -ComputerName SVR19-3
Get-DscConfigurationStatus -CimSession $session
# Manually force the LCM to run
Update-DscConfiguration -CimSession $session -Verbose -Wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment