我正在探索DSC并想知道将DSC资源复制到目标主机的最佳方法是什么?
当我尝试将配置推送到目标主机时,它抱怨缺少DSC资源。
The PowerShell DSC resource xWebAdministration does not exist at the PowerShell module path nor is it registered as a WMI DSC resource.
+ CategoryInfo : InvalidOperation: (root/Microsoft/...gurationManager:String) [], CimException
+ FullyQualifiedErrorId : DscResourceNotFound
+ PSComputerName : server1.appman.net
答案 0 :(得分:7)
确保资源可用的最简单方法是设置基于文件共享的存储库以下拉模块。此博客可以帮助您http://nanalakshmanan.com/blog/Push-Config-Pull-Module/
答案 1 :(得分:1)
我尝试使用DSC安装PS模块。它需要3个独立的配置:
Configuration InitialConfiguration
{
Import-DscResource -ModuleName 'PSDesiredStateConfiguration'
Node MyServer
{
Script InstallModule
{
SetScript = { Install-Module PackageManagement -MinimumVersion 1.1.7 -Force }
TestScript = { $version = (Get-Module PackageManagement -ListAvailable).Version; $version.Major -ge 1 -and $version.Minor -ge 1 }
GetScript = { Get-Module PackageManagement -ListAvailable }
}
}
}
Configuration ModulesConfiguration
{
Import-DscResource -ModuleName 'PackageManagement' -ModuleVersion 1.1.7.0
Node MyServer
{
PackageManagement xWebAdministration
{
Name = 'xWebAdministration'
}
}
}
Configuration WebServerConfiguration
{
Import-DscResource –ModuleName 'xWebAdministration'
Node MyServer
{
xWebAppPool SampleAppPool
{
Name = 'SampleAppPool'
}
}
}
但是,Microsoft使用simple script在example中使用WinRM安装模块。
答案 2 :(得分:0)
创建将安装模块的DSC配置,并且可以从网络共享中获取模块或更多可能从某些存储库(例如git)中检出它们,但当然如果他们可以访问它。推或拉最适合你。
答案 3 :(得分:0)
在PSModule路径中找不到模块时出现错误
使用以下行从PSGallery存储库Install-Module -Name xWebAdministration
当弹出窗口出现时,单击“Yes to All”,模块安装完毕
要交叉检查模块是否已安装,请键入
在PowerShell控制台中$env:PSModulePath
并在PS模块路径中找到xWebAdministration文件夹
答案 4 :(得分:0)
# Commands for pushing DSC Resource Modules to Target Nodes.
# Resources you want to push must be available on this Authoring Machine.
#Required DSC resource modules
$moduleNames = "XWebAdministration", "xSMBShare", "cNtfsAccessControl", "OctopusDSC", "PSDSCResources", "DSCR_Font"
#ServerList to push files to
$Servers = "C:\temp\serverList.txt"
$serverList = (get-content $Servers |
Where { $_ -notlike ";*" } | #lines that start with ';' will be considered comments
ForEach { $_ } |
select -Unique `
)
foreach ($server in $serverList)
{
$Session = New-PSSession -ComputerName $server
$getDSCResources = Invoke-Command -Session $Session -ScriptBlock {
Get-DscResource
}
foreach ($module in $moduleNames)
{
if ($getDSCResources.moduleName -notcontains $module){
#3. Copy module to remote node.
$Module_params = @{
Path = (Get-Module $module -ListAvailable).ModuleBase
Destination = "$env:SystemDrive\Program Files\WindowsPowerShell\Modules\$module"
ToSession = $Session
Force = $true
Recurse = $true
Verbose = $true
}
Copy-Item @Module_params
}
}
Remove-PSSession -Id $Session.Id
}