我对PowerShell DSC相当新,对此的回答可能非常明显,但我找不到任何地方描述的类似问题.
我有一个PowerShell DSC复合资源,可以下载一些MSI并运行它们.下载文件的目录在几个地方被引用,所以我试图将它存储在一个变量中.但是,当我来应用使用此资源的配置时,Start-DscConfiguration值始终显示为null.
以下是资源的示例:
Configuration xExample {
Import-Module -ModuleName 'PSDesiredStateConfiguration'
$path = 'C:\Temp\Installer.msi'
Script Download {
SetScript = {
Invoke-WebRequest -Uri "..." -OutFile $path
}
GetScript = {
@{
Result = $(Test-Path $path)
}
}
TestScript = {
Write-Verbose "Testing $($path)"
Test-Path $path
}
}
}
Run Code Online (Sandbox Code Playgroud)
当执行此资源时,详细输出显示"Testing",并且Test-Path由于Path参数为null ,调用失败.
我已经尝试$path在配置之外声明变量并且使用$global无效.
我错过了什么?
下面的DSC声明而不是HKEY_CURRENT_USER \ Console写入注册表项HKEY_USERS.DEFAULT \ Console。为什么?
Registry ConsoleFaceName
{
Key = 'HKEY_CURRENT_USER\Console'
ValueName = "FaceName"
ValueData = "Lucida Console"
Ensure = "Present"
}
Run Code Online (Sandbox Code Playgroud) 当我尝试使用 DSC 将网站(甚至是单个文件)复制到 VM 时,配置如下:
File WebSiteContent {
Ensure = "Present"
SourcePath = "https://MYBLOB.blob.core.windows.net/prod/index.html?sv=2016-05-31&ss=b&srt=s&sp=rl&se=2017-11-29T21:47:36Z&st=2017-07-26T13:47:36Z&spr=https&sig=SIG_HERE"
DestinationPath = "C:\inetpub\backend\app_data"
Type = "Directory"
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
[ERROR] Relative path is not supported. The related file/directory is: https://MYBLOB.blob.core.windows.net/prod/index.html?sv=2016-05-31&ss=b&srt=s&sp=rl&se=2017-11-29T21:47:36Z&st=2017-07-26T13:47:36Z&spr=https&sig=SIG_HERE. \r\n
不知道是什么原因,因为这是文件的绝对路径。任何使其工作的建议表示赞赏:)