1
votes

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.

2
I have the same issue: I run Powershell script from MSBuild as Exec task. I took the same command and then ran it in a CMD session, and it works. It works in every scenario aside being run from MSBuild. I am at lost here.Gerino

2 Answers

3
votes

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
0
votes

I hit the same issue.

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

Yup, it makes a difference.