Anyone know how to obtain the current DSC working folder?
On the server, when DSC runs, it generates a folder stucture like the following:
C:\Packages\Plugins\Microsoft.Powershell.DSC\2.18.0.0\DSCWork\DSC.0
The only trouble is when DSC gets a new version, it increments the ".X" folder.. However, when DSC runs, there is no clear way how to resolve the current folder from a script block predictably:
Script GetDscCurrentPath
{
TestScript = {
return $false
}
SetScript ={
Write-Verbose (Get-Item 'C:\%path_to_dsc%\FileInsideMyDscAsset.txt')
}
GetScript = { @{Result = "GetDscCurrentPath"} }
}
Thoughts? Thanks in advance!!!
The DSC Extension does not expose a variable or function to get the current working directory, but since your script / module is in the directory you should be able to use the PSScriptRoot to get the directory. Here is an example:
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} }
}
}