powershell DSC复制并使用模块运行本地

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell DSC复制并使用模块运行本地相关的知识,希望对你有一定的参考价值。

#-------------------------------------------------------
#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}
#-------------------------------------------------------

以上是关于powershell DSC复制并使用模块运行本地的主要内容,如果未能解决你的问题,请参考以下文章