I've developed a script in Powershell_ISE to backup a SQL Server database on one server, move the file to another server and restore to the target server with a different database name. Works fine.
It uses 6 mandatory parameters. Within Powershell_ISE I can run
C:\PowershellScripts\Servers\CRMBackup.ps1 -SrcSrv uk-sb-sql12\wss -SrcDb UAT_2016_MSCRM
-SrcBak \\uk-sb-sql12\backup\ -TrgSrv uk-sb-sql12\wss -TrgDb preprod_mscrm66 -TrgBak
\\uk-sb-sql12\backup\
and it works fine.
I can't get it to run from the Command Line though. How do I achieve this?
If I run
powershell_ise.exe "C:\PowershellScripts\Servers\CRMBackup.ps1" -SrcSrv uk-sb-sql12\wss
-SrcDb UAT_2016_MSCRM -SrcBak \\uk-sb-sql12\backup\ -TrgSrv uk-sb-sql12\wss -TrgDb
preprod_mscrm66 -TrgBak \\uk-sb-sql12\backup\
from a Command prompt I get an error:
If I call Powershell instead of Powershell_ISE, all is fine:
powershell.exe "C:\PowershellScripts\Servers\CRMBackup.ps1" -SrcSrv uk-sb-sql12\wss
-SrcDb UAT_2016_MSCRM -SrcBak \\uk-sb-sql12\backup\ -TrgSrv uk-sb-sql12\wss -TrgDb
preprod_mscrm66 -TrgBak \\uk-sb-sql12\backup\
completes successfully:
Can anyone advise how to pass command line parameters into Powershell_ISE?
Thanks
You cannot use parameters into Powershell_ISE from Command Line.
Some background:
You use PowerShell ISE to develop your scripts (or notepad or whatever) and you use powershell.exe to execute them when finished. You can execute scripts in different ways:
Of course you can execute scripts from PowerShell ISE while developing them that can be done by clicking Start (or pressing F5) and you can pass parameters as explained here . But you cannot execute an script passing parameters to powershell_ise.exe .
did you try this? (powershell.exe instead of powershell_ise.exe)
powershell.exe "C:\PowershellScripts\Servers\CRMBackup.ps1" -SrcSrv uk-sb-sql12\wss -SrcDb UAT_2016_MSCRM -SrcBak \\uk-sb-sql12\backup\ -TrgSrv uk-sb-sql12\wss -TrgDb preprod_mscrm66 -TrgBak \\uk-sb-sql12\backup\
Unfortunatelly you cannot start ISE from command line with your parameters. The list of possible parameters that could only customize your session is here:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.