alcaron

EX-DSCConfig.ps1

Feb 11th, 2014
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. & winrm quickconfig -force
  2.  
  3. if((Test-Path -Path "C:\scripts") -ne $true) {
  4.     try{ New-Item -Path "C:\scripts" -ItemType Directory }
  5.     catch {
  6.         Write-Host "Could not create scripts directory."
  7.         Break
  8.     }
  9. }
  10. $guid = $null
  11. try{ [xml]$xml = Get-Content -Path "\\dsc.bc.firm.local\DSC\Nodes\nodes.xml" }
  12. catch {
  13.     Write-Host $_.Exception.Message
  14.     Break
  15. }
  16. $guid = $xml.hostname.$env:computername.guid
  17. if($guid -eq $null) {
  18.     # At some point you want to phone home, either send an email or update a dashboard noting the failure.
  19.     # Or at the very least write to something more permanent than the screen...
  20.     Write-Host "Could not find a valid GUID, exiting..."
  21.     Break
  22. }
  23.  
  24. Configuration Setup {
  25.     param ($NodeId, $PullServer)
  26.  
  27.     LocalConfigurationManager {
  28.         AllowModuleOverwrite = $true
  29.         ConfigurationID = $NodeId
  30.         ConfigurationModeFrequencyMins = 15
  31.         ConfigurationMode = 'ApplyAndAutoCorrect'
  32.         RebootNodeIfNeeded = $false
  33.         RefreshMode = 'PULL'
  34.         DownloadManagerName = 'WebDownloadManager'
  35.         DownloadManagerCustomData = (@{ServerUrl = "http://$PullServer/PSDSCPullServer.svc";AllowUnsecureConnection = 'True'})
  36.     }
  37. }
  38.  
  39.  
  40. Setup -NodeId $guid -PullServer "<dscserver>" -OutputPath "C:\scripts"
  41. Set-DscLocalConfigurationManager -Path "C:\scripts"
  42.  
  43. Copy-Item -Path "\\<dscmoduleshare>\*" -Destination "C:\Windows\System32\WindowsPowerShell\v1.0\Modules" -Recurse -Force -Confirm:$false
  44. $proc = New-Object System.Diagnostics.Process
  45. $proc.StartInfo.FileName = "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
  46. $proc.StartInfo.Arguments = '-NonInt -Window Hidden -Command "Invoke-CimMethod -Namespace root/Microsoft/Windows/DesiredStateConfiguration -Cl MSFT_DSCLocalConfigurationManager -Method PerformRequiredConfigurationChecks -Arguments @{Flags = [System.UInt32]1}"'
  47. $proc.StartInfo.UseShellExecute = $true
  48.  
  49. $proc.Start()
  50. Start-Sleep -Seconds 180
  51. gps wmi* | ?{ $_.Modules.ModuleName -like "*DSC*" } | Stop-Process -Confirm:$false -Force
  52. $proc.Start()
Add Comment
Please, Sign In to add comment