Prerequisites
PSAppDeployToolkit version
4.0.3
Describe the bug
For some unknown reason, I can't get Invoke-AppDeployToolkit.exe to run properly from the PowerShell 7.
I always get the following error:

I noticed the process was blocked in Windows Explorer, I unblocked it and it didn't change anything.

I've tried using Windows Powershell and it worked just fine. So something must be different when executing from PowerShell 7.

From experience, I know code to detect the current script path varies depending on the version of PowerShell. If that's the case, here's a function to fix it. It could also be a great addition to PSADT.
Function Get-ScriptPath {
<#
.SYNOPSIS
Returns the current script's path no matter the PowerShell editor or version running.
.NOTES
Name: Get-ScriptPath
Version: 1.0
.EXAMPLE
Get-ScripPath
.LINK
#>
[CmdletBinding()]
Param(
[Parameter(
Mandatory = $false,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
HelpMessage = "Enter script's path",
Position = 0
)]
[string]$Path
)
Begin {
#$DebugPreference = 'Continue'
Set-StrictMode -Off
# Clear variable
If (-Not [string]::IsNullOrEmpty($scriptPath)) { Remove-Variable -Name scriptPath -Force -ErrorAction SilentlyContinue }
}
Process {
# Manual path entered
If ($Path) { $scriptPath = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path; $psEditorName = "Manual path" }
# Visual Studio Code
ElseIf (-not [String]::IsNullOrEmpty($psEditor)) { $scriptPath = Split-Path -Path $psEditor.GetEditorContext().CurrentFile.Path; $psEditorName = "Visual Studio Code" }
# PS1 converted to EXE
ElseIf ($MyInvocation.MyCommand.CommandType -eq 'ExternalScript') { $scriptPath = Split-Path -Path $My$MyInvocation.MyCommand.Source; $psEditorName = "Converted EXE" }
# Sapien PowerShell Studio
ElseIf (-not [String]::IsNullOrEmpty($HostInvocation)) { $scriptPath = $HostInvocation.MyCommand.Path; $psEditorName = "Sapien PowerShell Studio" }
# Windows PowerShell ISE
ElseIf (-not [String]::IsNullOrEmpty($psISE)) { $scriptPath = Split-Path -Path $psISE.CurrentFile.FullPath; $psEditorName = "Windows PowerShell ISE" }
# Windows PowerShell 3.0+
ElseIf (-not [String]::IsNullOrEmpty($MyInvocation.$PSScriptRoot)) { $scriptPath = $MyInvocation.PSScriptRoot; $psEditorName = "Windows PowerShell" }
ElseIf (-not [String]::IsNullOrEmpty($MyInvocation.MyCommand.Path)) { $scriptPath = Split-Path -Path $MyInvocation.MyCommand.Path -Parent; $psEditorName = "Windows PowerShell" }
# Windows PowerShell & Powershell
ElseIf (-not [String]::IsNullOrEmpty($PWD)) { $scriptPath = $PWD.Path; $psEditorName = "PowerShell" }
# When all else fails
Else { $scriptPath = (Get-Location).Path; $psEditorName = "Else" }
}
End {
If ([string]::IsNullOrEmpty($scriptPath)) {
Write-Host -Object "Unable to resolve script's file path!" -ForegroundColor Red
Start-Sleep -Seconds 3
Exit
}
Write-Debug -Message "PowerShell Editor: $psEditorName"
Write-Debug -Message "Script Path: $scriptPath"
return $scriptPath
}
}
Steps to reproduce
- Launch Windows Terminal as an admin or pwsh.exe
- Launch Invoke-AppDeployToolkit.exe
Environment data
OsName : Microsoft Windows 11 Business
OSDisplayVersion : 24H2
OsOperatingSystemSKU : 48
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsProductName : Windows 10 Pro
WindowsBuildLabEx : 26100.1.amd64fre.ge_release.240331-1435
OsLanguage : en-US
OsMuiLanguages : {en-US}
KeyboardLayout : en-US
TimeZone : (UTC-08:00) Pacific Time (US & Canada)
HyperVisorPresent : True
CsPartOfDomain : False
CsPCSystemType : Desktop
Prerequisites
PSAppDeployToolkit version
4.0.3
Describe the bug
For some unknown reason, I can't get Invoke-AppDeployToolkit.exe to run properly from the PowerShell 7.
I always get the following error:

I noticed the process was blocked in Windows Explorer, I unblocked it and it didn't change anything.

I've tried using Windows Powershell and it worked just fine. So something must be different when executing from PowerShell 7.

From experience, I know code to detect the current script path varies depending on the version of PowerShell. If that's the case, here's a function to fix it. It could also be a great addition to PSADT.
Steps to reproduce
Environment data