Call powershell Scripts

Hi,

I have requiremnt to call powershell scripts from another powershell script. I am using the below script. the script works fine, but the issue it opens 3 other Management Shell and runs the scripts and closes them and I am not able see any error message. Is there way where we can see the error message.


#Add SharePoint Snapin
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
start-process powershell.exe -verb runas "D:\SPDeployment\WPDeployment.ps1"
 
start-process powershell.exe -verb runas "D:\SPDeployment\AddColumn.ps1"

start-process powershell.exe -verb runas "D:\SPDeployment\SiteLogo.ps1"

#Remove SharePoint Snapin
Remove-PsSnapin Microsoft.SharePoint.Powe

April 4th, 2012 2:46pm

try passing -noexit to the your cmd, like

start-process powershell.exe -noexit -verb runas "ps script"
Make sure, noexit is the first argument passed to powershell.exe
Free Windows Admin Tool Kit Click here and download it now
April 4th, 2012 3:00pm

If the script is in the same folder then just write this statement

.\myscript.ps1

else

.\<foldername>\myscript.ps1

Thanks,

Bokes

April 5th, 2012 6:08am

If the script is in the same folder then just write this statement

.\myscript.ps1

else

.\<foldername>\myscript.ps1

Thanks,

Free Windows Admin Tool Kit Click here and download it now
April 5th, 2012 3:03pm

I tried this using the following script and got a PS error that -noexit was not a valid argument... So is there a special snap-in or something I need to do? 

{start-process powershell.exe -noexit -verb runas ".\myPowerShellScript.ps1"}

Am I doing this statement wrong?

July 7th, 2015 10:38am

You shouldn't use the ".\" in the Start-Process.

If I remember correctly it will just open powershell in its default path location e.g. "C:\System32" so the script will be looking there. 

Plus I am not sure Start-Process supports -noexit

The technet article says it doesnt

You will have to do the below.

start-process powershell.exe -verb runas -file c:\script.ps1 -NoNewWi		
Free Windows Admin Tool Kit Click here and download it now
July 8th, 2015 3:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics