Batman
Batman

Reputation: 6373

Post Build PowerShell Script does not include installed modules

I am calling the below script in my post build configurations:

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -file "\Sclddev8\tfs\Scripts\slack-notice.ps1" -Verb RunAs;

However, I keep getting this error:

Send-SlackMessage : The term 'Send-SlackMessage' is not recognized as the name

But I have installed this module in my environment and if I open a PowerShell console or run the file outside of this build process, works without issue.

Upvotes: 1

Views: 586

Answers (2)

Gerino
Gerino

Reputation: 1983

I hit the same issue.

What helped was... copying the folder into C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules.

Yup, it makes a difference.

Upvotes: 0

Bryce McDonald
Bryce McDonald

Reputation: 1870

When you install a Powershell module, you are technically importing the module from your profile every time you open a new Powershell window. By running Powershell with the "-NoProfile" switch, you're preventing the module from being imported (even though it's "installed" and the files are present).

What may be your best option, if you want to keep the "-NoProfile" switch active, is to have a line at the top of your script to import the module before continuing. If you're using Warren Frame's "PSSlack" module, the command you need is:

> Import-Module PSSlack

Upvotes: 3

Related Questions