DscTemplate 没有执行我的 SetScript
DscTemplate isn't executing my SetScript
$Launcher_PackageFile = "Launcher.exe"
$Launcher_PackageDestinationDirectory = "$Env:ProgramData\Launcher";
#$Launcher_StartupDirectory = (New-Object -ComObject Shell.Application).NameSpace(0x07)
$Launcher_Source = "$Env:PackageRoot\Launcher$Launcher_PackageFile"
Script UpdateConfigurationVersion
{
GetScript = {
# For cmdlet. Must always return a hash table.
return @{
"Name"="LauncherPackage"
"Version"="Latest"
};
}
TestScript = {
# Check if the file is in the folder
$TestPath = Join-Path $Launcher_PackageDestinationDirectory $Launcher_PackageFile
if (Test-Path $TestPath) {
return $true;
}
return $false;
}
SetScript = {
# Logic
#move the exe
if (!Test-Path $Launcher_PackageDestinationDirectory) {
New-Item -Type Directory -Path $Launcher_PackageDestinationDirectory
}
Copy-Item -Path $Launcher_Source -Destination $Launcher_PackageDestinationDirectory
#TODO Create a shortcut to the startup directory
#or create a task in the scheduler
}
}
有了那个信息就很难说了。
将消息添加到 TestScript 和 SetScript 以查看发生了什么。例如:
Write-Verbose -Message 'Testing if already exists'
TestScript 在 SetScript 之前执行,检查是否返回 true 或 false(通过添加消息)。 TestScript 可能返回 true,因此 SetScript 不是 运行。输出$TestPath看路径是否正确。
然后查看C:\Windows\System32\Configuration\ConfigurationStatus
上的日志
语法不正确
(!测试路径
if (!(Test-Path $Launcher_PackageDestinationDirectory)) {....
或
if (-not(Test-Path $Launcher_PackageDestinationDirectory) {....
同时将 -ErrorAction SilentlyContinue
添加到您的 Test-Path
命令以抑制错误。
$Launcher_PackageFile = "Launcher.exe"
$Launcher_PackageDestinationDirectory = "$Env:ProgramData\Launcher";
#$Launcher_StartupDirectory = (New-Object -ComObject Shell.Application).NameSpace(0x07)
$Launcher_Source = "$Env:PackageRoot\Launcher$Launcher_PackageFile"
Script UpdateConfigurationVersion
{
GetScript = {
# For cmdlet. Must always return a hash table.
return @{
"Name"="LauncherPackage"
"Version"="Latest"
};
}
TestScript = {
# Check if the file is in the folder
$TestPath = Join-Path $Launcher_PackageDestinationDirectory $Launcher_PackageFile
if (Test-Path $TestPath) {
return $true;
}
return $false;
}
SetScript = {
# Logic
#move the exe
if (!Test-Path $Launcher_PackageDestinationDirectory) {
New-Item -Type Directory -Path $Launcher_PackageDestinationDirectory
}
Copy-Item -Path $Launcher_Source -Destination $Launcher_PackageDestinationDirectory
#TODO Create a shortcut to the startup directory
#or create a task in the scheduler
}
}
有了那个信息就很难说了。
将消息添加到 TestScript 和 SetScript 以查看发生了什么。例如:
Write-Verbose -Message 'Testing if already exists'
TestScript 在 SetScript 之前执行,检查是否返回 true 或 false(通过添加消息)。 TestScript 可能返回 true,因此 SetScript 不是 运行。输出$TestPath看路径是否正确。
然后查看C:\Windows\System32\Configuration\ConfigurationStatus
上的日志语法不正确 (!测试路径
if (!(Test-Path $Launcher_PackageDestinationDirectory)) {....
或
if (-not(Test-Path $Launcher_PackageDestinationDirectory) {....
同时将 -ErrorAction SilentlyContinue
添加到您的 Test-Path
命令以抑制错误。