-
1. Re: Launch PowerShell Script with nsh script
Edwin Lindeman Feb 19, 2015 2:29 PM (in response to Ben 10)this works for me
nexec -i -e cmd /c "echo |.powershell C:\directory\myscript.ps1"
from this article
-
2. Re: Launch PowerShell Script with nsh script
STEFANO BRUTTO Feb 19, 2015 2:35 PM (in response to Edwin Lindeman)i hope in the future a real powershell integration in bsa...
-
3. Re: Launch PowerShell Script with nsh script
Ben 10 Feb 19, 2015 2:36 PM (in response to Edwin Lindeman)And if I want to add the parameter $serverName and execute the command on a target host.
It's alright if I use this command?:
nexec server.company.com -i -e cmd /c"echo |.powershell C:\directory\myscript.ps1 $serverName"
If I copy/paste this command, there's Will working or they have some error on it?
Thanks!
-
4. Re: Launch PowerShell Script with nsh script
STEFANO BRUTTO Feb 19, 2015 2:39 PM (in response to Ben 10)replace the server.company.com with a $targetserver variable...
-
5. Re: Launch PowerShell Script with nsh script
Edwin Lindeman Feb 19, 2015 2:51 PM (in response to Ben 10)Yes that will work
-
6. Re: Launch PowerShell Script with nsh script
Ben 10 Feb 19, 2015 2:57 PM (in response to STEFANO BRUTTO)ok! Thanks!
Now I got this error: "The system cannot find the file specified."
But, I verify the name and the folder and the script is already here.
nexec $targetserver -i -e cmd /c"echo |.powershell C:\BLScript\script.ps1 $serverName"
There's something that I missing?
-
7. Re: Launch PowerShell Script with nsh script
Bill RobinsonFeb 19, 2015 3:11 PM (in response to Ben 10)
escape the slashes ??
-
8. Re: Launch PowerShell Script with nsh script
Ben 10 Feb 20, 2015 10:18 AM (in response to Bill Robinson)I tried:
nexec $targetserver -i -e cmd /c"echo |.powershell C:\BLScript\script.ps1 $serverName"
nexec $targetserver -i -e cmd /c"echo |.powershell C:/BLScript/script.ps1 $serverName"
nexec $targetserver -i -e cmd /c"echo |.powershell \C\\BLScript\\script.ps1 $serverName"
Still the same. I got the error "The system cannot find the file specified."
Any idea about this?
-
9. Re: Launch PowerShell Script with nsh script
Edwin Lindeman Feb 20, 2015 10:23 AM (in response to Ben 10)im assuming your target server has powershell installed and that path and script exist? Best Regards
-
10. Re: Launch PowerShell Script with nsh script
Ben 10 Feb 20, 2015 10:38 AM (in response to Edwin Lindeman)Yes Powershell is installed on the server et the path and script exist.
I copy/paste the name of the script for minimize error.
Really don't understand why is not working.
-
11. Re: Launch PowerShell Script with nsh script
Edwin Lindeman Feb 20, 2015 10:43 AM (in response to Ben 10)not sure if this matters is there a space between /c"echo ?
the -e option i thought was if code was running on the machine your executing from for remote try the below.. basically without -e
nexec -i $targetserver cmd /c "echo .powershell C:\BLScript\script.ps1 ${serverName}"
-
12. Re: Launch PowerShell Script with nsh script
Bill RobinsonFeb 20, 2015 11:42 AM (in response to Edwin Lindeman)
nexec $targetserver -i -e cmd /c"powershell -inputformat NONE C:\\BLScript\\script.ps1 $serverName"
? and that assumes powershell in the default path on the target server.
-
13. Re: Launch PowerShell Script with nsh script
Raja Mohan Feb 20, 2015 3:06 PM (in response to Ben 10)Ben 10 This is how we were able to run powershell scripts through nexec. Hope it helps
nexec $HOSTNAME cmd -e /c "powershell.exe -executionpolicy bypass -command "C:\file-location\file-name.ps1""
where the hostname is the windows server you want to execute powershell script on
-
14. Re: Launch PowerShell Script with nsh script
Ben 10 Feb 25, 2015 1:52 PM (in response to Raja Mohan)Hello everyone,
I found this command: `nexec server.abc.com cmd /c Powershell.exe -ExecutionPolicy ByPass -InputFormat None -OutputFormat Text -NoLogo -NonInteractive -Command "(C:\BLScript\Script.ps1)"` that's seen to be working.
But now, i got an another problem. The script is running with the BladelogicRSCD account.
There's a way to run the powershell with another user or with the automation principal?
Thanks!