Dustin,
I just tried, and it just opened the script in Notepad. The .ps1 scripts by default needs Powershell. You can create some kind of link or target that will call powershell and feed the script to it. In the agent, you will have to define the powershell as command and then args will ps1 script.
As for script calling other scripts, use LastExitCode and %ERRORLEVEL% to pass the non-zero exit code.
E.g. batch running powershell
powershell "&{C:\tmp\my.ps1 %* ;exit $LastExitCode}" set code=%errorlevel%
HTH,
Nitin Pande
------------------------------
Support
Broadcom
Toronto
------------------------------
Original Message:
Sent: 05-12-2021 09:07 AM
From: Dustin Neely
Subject: Executing powershell scripts
Nitin are you sure?
I ask because powershell scripts can be double clicked on within windows and they execute just fine but cannot be defined on the CMDNAME line
Original Message:
Sent: 5/12/2021 9:04:00 AM
From: Nitin Pande
Subject: RE: Executing powershell scripts
Hi,
This will not work, because .ps1 are not executable by itself.
CMDNAME F:\jobs\job.ps1
You will need to use powershell.exe to call script. Any script or command that you can double click on Windows can be defined in CMDNAME.
HTH,
Nitin Pande
------------------------------
Support
Broadcom
Toronto
Original Message:
Sent: 05-11-2021 11:50 AM
From: Dustin Neely
Subject: Executing powershell scripts
We currently do it like this
NT_JOB
RUN ANYDAY
CMDNAME C:\program files\powershell\7\pwsh.exe
ARGS F:\job\job.ps1
ENDJOB
I would like to do it like this
NT_JOB
RUN ANYDAY
CMDNAME F:\jobs\job.ps1
Endjob.
Adding a bat file in the mix adds another layer of potential issues. For instance if a powershell script runs just fine but then the cmd that the .bat was called from fails we get a failure returned when it was actually successful. Just trying to reduce the number of components if possible.
Please see the following link for the BlueCross BlueShield of Tennessee E-mail disclaimer:
https://www.bcbst.com/about/our-company/corporate-governance/privacy-security/email-policy.page
Original Message:
Sent: 5/11/2021 11:47:00 AM
From: Rick Romanowski
Subject: RE: Executing powershell scripts
You could create a Window Batch file PS1.bat
PS1.bat
powershell <fully qualified path/name of PowerShell Script>
Create a Windows Job
NT_JOB PS1BAT
AGENT <Agent Name>
CMDNAME <Path to Batch file>\PS1.bat
RUN ANYDAY
ENDJOB
Would that provide what you need?
------------------------------
Senior Systems Analyst
UPS
United States
Original Message:
Sent: 05-11-2021 11:29 AM
From: Dustin Neely
Subject: Executing powershell scripts
Good morning everyone,
I am wondering if there is an option for windows agents to set a default terminal like there is for linux/unix agents?
We currently are calling powershell.exe and then passing script as an argument but I would like to just call the powershell script itself. This just gives an sub error right now.
I have associated the ps1 with powershell.exe so that it understand what command interpreter to use, but still not working.
------------------------------
Thanks for any help in advance
Dustin.
Lead DevOps Scheduler
Blue Cross Blue Shield Of Tennessee
------------------------------