1

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.

1
  • 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. Commented Mar 30, 2019 at 23:55

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

8 Comments

tried and got this: "Import-Module : The specified module 'PSSlack' was not loaded because no valid module file was found in any module directory."
You may need to reference the actual .psm1 then. Import-Module C:\Users\UserName\Documents\WindowsPowerShell\Modules\PSSlack\PSSlack.psm1
Thank you that worked. I'm not sure why it's not find these things without having to provide the full path, that's strange.
I'll be honest, I'm not exactly sure how out of bounds "-NoProfile" plays into things. I'd be willing to bet that it even runs as a dummy user's process, so it has no environment profile path to follow. As much as NoProfile is a best practice, I've run into more trouble with it than anything. When you're using it, it's best to be explicit on everything else you're calling.
Any ideas on how to provide arguments to %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Unrestricted -file "\\Sclddev8\tfs\Scripts\slack-notice.ps1 -myParam $(TargetDatabase)" -Verb RunAs;"
|
0

I hit the same issue.

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

Yup, it makes a difference.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.