Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active June 10, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techthoughts2/989ee16c2b1d56438e30c0ec9567317d to your computer and use it in GitHub Desktop.
Save techthoughts2/989ee16c2b1d56438e30c0ec9567317d to your computer and use it in GitHub Desktop.
Instead of a direct DSC push, this example shows a method where the MOF is copied to the destination node along with any DSC modules required. Once on the destination, the DSC is then applied locally. This operates in much the same manner as DSC push
#-------------------------------------------------------
#add a trusted source - only if required
#winrm s winrm/config/client '@{TrustedHosts="783721-hyp41,10.127.57.25"}'
#-------------------------------------------------------
#specify test device details and load up credentials
$s1 = "SERVER1"
$creds = Get-Credential -Message "Enter Credentials"
#-------------------------------------------------------
#create remote session with the appropriate options for your environment
$so = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
$session = New-PSSession -ComputerName $s1 -Credential $creds -SessionOption $so -UseSSL
#-------------------------------------------------------
#copy the localhost mof to the test device using previously established session
$params = @{
Path = 'C:\DSC\Test\localhost.mof'
Destination = 'C:\rs-pkgs\localhost.mof'
ToSession = $session
}
Copy-Item @params -Recurse -Force
#-------------------------------------------------------
#copy the required modules to the test device
$paramsDefender = @{
Path = 'C:\Program Files\WindowsPowerShell\Modules\xNetworking'
Destination = 'C:\Program Files\WindowsPowerShell\Modules'
ToSession = $session
}
Copy-Item @paramsDefender -Recurse -Force
#-------------------------------------------------------
#invoke a Start-DSCConfiguration command that will run *locally* on the destination device using the localhost.mof just copied
Invoke-Command -Session $session `
-ScriptBlock {Start-DSCConfiguration -Path C:\rs-pkgs -Wait -Verbose -Force}
#-------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment