Requirements and restrictions to run PowerShell scripts inside the Batchcontroller:
$PSVersionTableset-executionpolicy remotesigned -Scope LocalMachineUsage of "$MyInvocation" inside the scripts and Avanade script libraries must be removed, as not all properties are filled because of limits from Microsoft automation.
For example when you have the following code:
$ScriptPath = (Split-Path $MyInvocation.MyCommand.Path)
.$ScriptPath"\AmtSettings.ps1"It must be changed to:
.".\AmtSettings.ps1"The script has the folder it is located in, set as current folder by default.
Getting the script name is typically coded as follows:
$Base = Get-Item $myInvocation.ScriptName | select BaseName
return $Base.BaseNameWhich can be changed to:
$AmtScriptName = "$env:AMTJOBNAME"
if (-not ([String]::IsNullOrEmpty($AmtScriptName))) {
return $AmtScriptName
}When run inside the Batchcontroller, the environment variable "AMTJOBNAME" is set to the active script.
Any "Exit" statement must also set a PowerShell variable "$Global:AmtExitCode" for the Batchcontroller to read it correctly:
Change from:
Exit $ExitCodeTo:
$Global:AmtExitCode = $ExitCode
Exit $ExitCode