Null-valued Expression - $moduleAppDeployToolkitMain

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

I am probably not the only one unsure how to help troubleshoot this as you have not given any context as to the content of your Deploy-Application.ps1.
What application are you aiming to wrap in PSADT?
What changes have you made to the Deploy-Application.ps1 file to install the app?

FYI: The PSADT Docs are a good source of how to use the Toolkit:

p.s.

You cannot call a method on a null-valued expression.
At C:\Users\$user\Desktop\FM2020PSADT\Deploy-Application.ps1:167 char:13
. $moduleAppDeployToolkitMain

This is probably occuring because a variable defined (in the Deploy-Application.ps1 has not been populated - but without sight of your Deploy-Application.ps1 it is difficult to guess what this might be)

1 Like