I'm trying to get Powershell to run my PS script in post built - but somehow it doesn't work like it's supposed to:
Following command in Post-Build:
C:\WINDOWS\system32\windowspowershell\1.0\powershell.exe
-Command "& $(MSBuildProjectDirectory)\CreateSite.ps1 'auto'"
(inserted line break for better reading)
The command executes the powershell script sucessfully, but what it can't do is run the commands within (Output from Build): Rund Post-Build Command:
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2
At C:\path\CreateSite.ps1:4 char:
38
+ Add-PsSnapin <<<< Microsoft.SharePoint.PowerShell}
+ CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShell:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
And following that are many errors because all subsequent commands need the Sharepoint Snap-In.
- When running powershell C:\path\CreateSite.ps1 auto from cmd - everything works.
- When opening powershell.exe and running C:\path\CreateSite.ps1 auto - everything works.
- When right clicking CreateSite.ps1 --> run with powershell - everything works.
The relevant line in the script is simply Add-PsSnapin Microsoft.SharePoint.PowerShell.
How can I just run the darn script (and get it to include the PSSnapIn) passing it a parameter in Visual Studio post-build?