Search code examples
powershelltfstfs-2015

Module cannot be loaded error running PowerShell script in TFS 2015 build


I've got a PowerShell script that I'm using to validate that some SQL programming requirements are met.

The script is being run at the start of a Gated Build within TFS 2015 and seemingly completes successfully. I added a Write-Host line at the very end of the script with nothing after it and the logging for the step shows that text so I know the line is being hit before the error is thrown.

Despite everything seemingly completing without error or issue, I am getting a "ObjectNotFound" exception claiming that the module cannot be loaded.

What is interesting is that the module it is trying to load is the "DOMAIN\UserName". As I've noted, there is no more script after the last line written to the log.

Has anyone experienced this issue before and/or does anyone know why this might be happening?


Solution

  • So I figured out the issue.

    I was passing in a TFS variable for the source branch (in this case, the shelve-set created for the gated build) but I was not wrapping the value in quotes. What I didn't realize is that the source branch value in this instance consists of the shelve-set name and the user name associated with it :

    e.g. Gated_2019-03-18_01.40.16.1334;DOMAIN\UserName

    By not wrapping the argument in quotes I was causing it to be split on the semicolon separator and the "DOMAIN\UserName" associated with the Gated Build shelve-set was being treated as if it were a module to load.

    As soon as I wrapped the argument in quotes the issue went away.