Archive: Run Powershell script using NSIS


Run Powershell script using NSIS
Hi,

I am creating a setup file to deploy sharepoint WebApplication. I will have to first create a web application on the IIS and SharePoint Farm. For this I have a Powershell script which will do all that for me. I wanted to execute this powershell script using nsis.
I tried this :
SetOutPath $INSTDIR\CGD
File Files\CGDirectSiteInstallation.ps1
Execwait "$INSTDIR\CGD\CGDirectSiteInstallation.ps1"
but I am not able to execute this PS1 file.
Also this PS1 file will accept some parameters which will be taken from user.

Please let me know if I am doing anything wrong or how to execute this ps1 file?
Execution of this ps1 file should be silent.

Thanks & regards,
Mayur Mahajan


You only ExecWait executable files. Use ExecShell to open/launch a file with its default registered application.
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.1.3


Running SharePoint Powershell in NSIS
Thanks a lot for the quick reply.

But I am getting some problem for running the ps1 file through NSIS. It is as follows :
I have used some SharePoint commands like "New-SPAuthenticationProvider" and "New-SPWebApplication". So while executng these commands it gives me following errors :
"The term 'New-SPAuthenticationProvider' is not recognized as the name of a cmdlet, function, script file, or operable program."

To make this execute properly I tried to execute Add-PSSnapin command which is as follows : "Add-PSSnapin Microsoft.SharePoint.PowerShell".
After executing this command I am getting an error as :
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2

I tried to get solution on google, but in vein.

If I ran the same ps1 file through SharePoint Powershell then I didn't get any errors and the Web Application gets created successfully.

Please suggest a way to get out of this. Is there any other method through which we can create web application on IIS as well as on SharePoint Farm?


Thanks & regards,
Mayur Mahajan.


I've no idea what powershell is, but if you need to run the script through powershell, I suggest you try to execute powershell with your ps1 file as a parameter.


Originally posted by MSG
I've no idea what powershell is, but if you need to run the script through powershell, I suggest you try to execute powershell with your ps1 file as a parameter.
Thanks MSG,

I got my problem and meed some help in solving it.
The problem was, to run SharePoint commands I should run the SharePoint script in SharePoint Management shell. So I converted the windows powershell (the window which gets opened after executing ExceShell command) to SharePoint Management shell.
But for now the problem I am getting is, as the Windows Poershell gets converted to SharePoint Management Shell the window gets close. It should not get closed.

Please suggest me solution for this or else suggest another way to create Web Application on IIS, while running the setup file.

My requirement is when the setup starts it should create a new web application on IIS and then SharePoint Farm.

Please do let me know about this. I have been doing work on this since very long time and the NSIS and NSIS is the last hope.

Or else can you please suggest me how to open SharePoint Powershell (i.e. SharePoint Management Shell) directly.
I meant to say that, when we use ExecShell command then it opens Windows Powershell. So can we directly open the SharePoint Powershell (i.e. Sharepoint Management Shell)


http://social.technet.microsoft.com/...b-1f101de9e583

http://dmitrysotnikov.wordpress.com/...in-a-bat-file/