Run Powershell through VBScript.

Dec 19, 2011 at 10:34 AM
Edited Dec 19, 2011 at 10:35 AM



I am creating a msi package to deploy wsp on SharePoint application. For this I am first creating a web application on IIS and SharePoint Farm. I wanted to use ps1 script for this. I am trying to run a ps1 script from the msi but it's not working. when it starts executing a SharePoint commands (i.e New-SPWebApplication) it gives an error as the commands are not recognized. To overcome this problem I tried to convert cmd to SharePoint Management shell. For this I wrote the following command in ps1 file before executing any of the SharePoint command :

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -NoExit  " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' "

After this command gets executed, the cmd gets converted to SharePoint Managemenrt Shell but the moment it gets converted to Management shell, the window gets colsed. Latter I tried to call this powershell script through VBScript. To execute the script I used following command :

strRunCmd = "Powershell -command D:\DemoProject\CGDirectSiteInstallation.ps1 -Argument1 '"+ appUser + "' -Argument2 '"+ appPassword + "'"

With this way I am sccessfully able to run the ps1 script. The ps1 script first creates web application and then site collection and then Assessment Service. So when the script execution started it executes New-SPWebApplication and New-SPSite commands but didn't creates the web application and Site Collection, but It successfully creates Assessment Service. The script is working perfect. I tested it with SharePoint Management Shell and it's working fine.

Can anyone get me out of this? Do anyone have any solution for directly creating web application and Site Collection programatically.

I tried to do this through Custom actions with C# code but it is giving me some compatibilty issues.


Thanks & Regards,

Mayur Mahajan