任何人都知道如何获取当前的DSC工作文件夹?
在服务器上,当DSC运行时,它会生成如下文件夹结构:
C:\包\插件\ Microsoft.Powershell.DSC \ 2.18.0.0 \ DSCWork \ DSC.0
唯一的麻烦是当DSC获得新版本时,它会增加" .X"文件夹..然而,当DSC运行时,没有明确的方法可以预测如何从脚本块解析当前文件夹:
Script GetDscCurrentPath
{
TestScript = {
return $false
}
SetScript ={
Write-Verbose (Get-Item 'C:\%path_to_dsc%\FileInsideMyDscAsset.txt')
}
GetScript = { @{Result = "GetDscCurrentPath"} }
}
思考?在此先感谢!!!
答案 0 :(得分:2)
DSC扩展不公开变量或函数来获取当前工作目录,但由于您的脚本/模块位于目录中,因此您应该能够使用PSScriptRoot来获取目录。这是一个例子:
Write-Verbose -Message "PSScriptRoot: $PSScriptRoot" -Verbose
# Note PSScriptRoot will change when the extension executes
# your configuration function. So, you need to save the value
# when your configuration is loaded
$DscWorkingFolder = $PSScriptRoot
configuration foo {
Script GetDscCurrentPath
{
TestScript = {
return $false
}
SetScript ={
Write-Verbose $using:DscWorkingFolder
}
GetScript = { @{Result = $using:DscWorkingFolder} }
}
}