[Initial]
Message=Starte PowerShell Script...
DefVar $ExitCode$
DefVar $FileName$
DefVar $Hostname$
DefVar $KeyPath$

[Actions]
ShowBitmap "%ScriptPath%\logo.png" "PowerShell"
Sub_PrepInstall
DosInAnIcon_Setup
Sub_HandleExitCode
ExitWindows /Reboot

[Sub_PrepInstall]
Set $FileName$ = GetProductProperty("filename", "start")
if ($FileName$ = "")
    Set $FileName$ = "start"
endif
Set $Hostname$ = Lower(Trim(TakeString(0, GetReturnListFromSection("opsiservicecall_GetHostname"))))
Set $KeyPath$ = "\\" + $Hostname$ + "\appdata\%installingProdName%\"
if not(FileExists($KeyPath$+ $FileName$ + ".ps1"))
    LogError "Fatal: File " + $FileName$ + ".ps1 not found."
    IsFatalError
endif

[opsiservicecall_GetHostname]
"method":"iserv_cfg"
"params":[
  "Hostname"
]

[DosInAnIcon_Setup]
@echo off
pushd "\\iserv\appdata\%installingProdName%"
powershell -ExecutionPolicy Bypass -File "$FileName$.ps1"

[Sub_HandleExitCode]
Set $ExitCode$ = GetLastExitCode
comment "DISM exit code: " + $ExitCode$
if not($ExitCode$ = "0")
    LogError "Fatal: DISM quit with exit code " + $ExitCode$
    IsFatalError
endif
