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复制并使用模块运行本地的主要内容,如果未能解决你的问题,请参考以下文章

AzureVM 上的 Powershell DSC xChrome 示例失败

11.PowerShell DSC之安装PowerShell Module

使用 PowerShell DSC 安装 VS 2019

从 Azure ARM 模板 DSC 扩展,模块无法导入,因为在此系统上禁用了正在运行的脚本

PowerShell DSC:数据源无法处理筛选器

将 PowerShell DSC 与 ITSM/变更管理集成