Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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