Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- & winrm quickconfig -force
- if((Test-Path -Path "C:\scripts") -ne $true) {
- try{ New-Item -Path "C:\scripts" -ItemType Directory }
- catch {
- Write-Host "Could not create scripts directory."
- Break
- }
- }
- $guid = $null
- try{ [xml]$xml = Get-Content -Path "\\dsc.bc.firm.local\DSC\Nodes\nodes.xml" }
- catch {
- Write-Host $_.Exception.Message
- Break
- }
- $guid = $xml.hostname.$env:computername.guid
- if($guid -eq $null) {
- # At some point you want to phone home, either send an email or update a dashboard noting the failure.
- # Or at the very least write to something more permanent than the screen...
- Write-Host "Could not find a valid GUID, exiting..."
- Break
- }
- Configuration Setup {
- param ($NodeId, $PullServer)
- LocalConfigurationManager {
- AllowModuleOverwrite = $true
- ConfigurationID = $NodeId
- ConfigurationModeFrequencyMins = 15
- ConfigurationMode = 'ApplyAndAutoCorrect'
- RebootNodeIfNeeded = $false
- RefreshMode = 'PULL'
- DownloadManagerName = 'WebDownloadManager'
- DownloadManagerCustomData = (@{ServerUrl = "http://$PullServer/PSDSCPullServer.svc";AllowUnsecureConnection = 'True'})
- }
- }
- Setup -NodeId $guid -PullServer "<dscserver>" -OutputPath "C:\scripts"
- Set-DscLocalConfigurationManager -Path "C:\scripts"
- Copy-Item -Path "\\<dscmoduleshare>\*" -Destination "C:\Windows\System32\WindowsPowerShell\v1.0\Modules" -Recurse -Force -Confirm:$false
- $proc = New-Object System.Diagnostics.Process
- $proc.StartInfo.FileName = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
- $proc.StartInfo.Arguments = '-NonInt -Window Hidden -Command "Invoke-CimMethod -Namespace root/Microsoft/Windows/DesiredStateConfiguration -Cl MSFT_DSCLocalConfigurationManager -Method PerformRequiredConfigurationChecks -Arguments @{Flags = [System.UInt32]1}"'
- $proc.StartInfo.UseShellExecute = $true
- $proc.Start()
- Start-Sleep -Seconds 180
- gps wmi* | ?{ $_.Modules.ModuleName -like "*DSC*" } | Stop-Process -Confirm:$false -Force
- $proc.Start()
Add Comment
Please, Sign In to add comment