Hey guys,
I am very new to PSADT and having issues with my first script. I keep getting an error when it tries to open the AppDeployToolkitMain.ps1. I narrowed it down to a specific area of the code but everything looks fine until it tries to open AppDeployToolkit.ps1. I ended up downloading and replacing AppDeployToolkitMain.ps1 to see if that would fix it but no luck.
Code
## Variables: Environment
If (Test-Path -LiteralPath 'variable:HostInvocation') {
$InvocationInfo = $HostInvocation
Write-Host "HostInvocation"
}
Else {
$InvocationInfo = $MyInvocation
wRITE-Host "MyInvocation"
}
Write-Host $InvocationInfo
Write-Host $InvocationInfo.MyCommand.Definition
[String]$scriptDirectory = Split-Path -Path $InvocationInfo.MyCommand.Definition -Parent
Write-Host $scriptDirectory
## Dot source the required App Deploy Toolkit Functions
Try {
[String]$moduleAppDeployToolkitMain = "$scriptDirectory\AppDeployToolkit\AppDeployToolkitMain.ps1"
If (-not (Test-Path -LiteralPath $moduleAppDeployToolkitMain -PathType 'Leaf')) {
Write-Host "1"
Throw "Module does not exist at the specified location [$moduleAppDeployToolkitMain]."
}
If ($DisableLogging) {
Write-Host "2"
. $moduleAppDeployToolkitMain -DisableLogging
}
Else {
Write-Host "3"
Write-Host "$moduleAppDeployToolkitMain"
. $moduleAppDeployToolkitMain
}
}
Catch {
If ($mainExitCode -eq 0) {
[Int32]$mainExitCode = 60008
}
Write-Error -Message "Module [$moduleAppDeployToolkitMain] failed to load: `n$($_.Exception.Message)`n `n$($_.InvocationInfo.PositionMessage)" -ErrorAction 'Continue'
## Exit the script, returning the exit code to SCCM
If (Test-Path -LiteralPath 'variable:HostInvocation') {
$script:ExitCode = $mainExitCode; Exit
}
Else {
Exit $mainExitCode
}
}
Results
PS C:\Users\$user\Desktop\FM2020PSADT> .\Deploy-Application.ps1
MyInvocation
System.Management.Automation.InvocationInfo
C:\Users\$user\Desktop\FM2020PSADT\Deploy-Application.ps1
C:\Users\$user\Desktop\FM2020PSADT
3
C:\Users\$user\Desktop\FM2020PSADT\AppDeployToolkit\AppDeployToolkitMain.ps1
Write-Error: Module [C:\Users\$user\Desktop\FM2020PSADT\AppDeployToolkit\AppDeployToolkitMain.ps1] failed to load:
You cannot call a method on a null-valued expression.
At C:\Users\$user\Desktop\FM2020PSADT\Deploy-Application.ps1:167 char:13
. $moduleAppDeployToolkitMain
Any ideas what might be causing this issue?
Edit: The .exe seems to work weirdly enough