如何告诉DSC我需要先更新PowerShell本身?
我是否只使用脚本资源并安装chocolatey然后使用choco
安装最新的WMF / PowerShell?
答案 0 :(得分:1)
我已经写了一个样本来做这件事。我假设您使用PowerShell 4.0并希望更新到5.0,但概念是相同的。以下是完整sample的链接。
Set-ExecutionPolicy remotesigned
Set-WSManQuickConfig -Force
$nugetPath = Join-Path $env:temp nuget.exe
if(!(Test-Path $nugetPath))
{
Invoke-WebRequest -UseBasicParsing -Uri https://nuget.org/nuget.exe -OutFile $nugetPath
}
&$nugetPath install XWindowsUpdate -source https://www.powershellgallery.com/api/v2 -outputDirectory "$env:programfiles\WindowsPowerShell\Modules\ " -ExcludeVersion
Configuration WMF5Install
{
Import-DscResource -ModuleName xWindowsUpdate
Node localhost
{
xHotfix HotfixInstall
{
Path = 'E:\WindowsBlue-KB3055381-x64.msu'
Id = 'KB3055381'
Ensure = 'Present'
}
LocalConfigurationManager
{
RebootNodeIfNeeded = $true
}
}
}
$outputPath = Join-Path $env:temp Wmf5Install
WMF5Install -OutputPath $outputPath
Set-DscLocalConfigurationManager -Path $outputPath -Verbose
Start-DscConfiguration -Path $outputPath -Wait -Verbose -force