cancel
Showing results for 
Search instead for 
Did you mean: 
cancel

How To: Powershell on a Windows Agent

1806
Views
5
Helpful
2
Comments

Usually the way I tell people to run powershell jobs to ensure output, and that they are running 64-bit versions of the cmd.exe and the powershell.exe is to drag those two exe files into the Agent/Bin directory. If you don't do this, then windows will force the 32-bit agent to only run 32-bit versions of powershell.exe EVEN IF you explicitly point to the 64-bit version in windows/system32 -- it'll still redirect to windows/SysWOW64 to use the 32-bit versions. This is a bug with the Windows operating system. Very often powershell scripts running in the wrong bit-version have errors in the script.

The way I do it is like this:

1.) Copy windows/system32/cmd.exe and windows/system32/powershell.exe into the Agent/Bin directory

2.) In the job definition:

command: /path/to/Agent/Bin/cmd.exe
parameter: /c "/path/to/Agent/Bin/powershell.exe --parameters /path/to/script"

 

 

This will ensure that the 64-bit versions are running by the agent. If you run it this way, the output will be printed to the output tab of the job. No need to write a batch script to call the powershell script.

A good way to verify the bit version the job is running inside is to open a task manager on the agent machine and look at the cmd.exe tasks. If the job becomes active and the new cmd.exe has nothing after it, it is 64-bit. If it has (32-bit) after, it is 32-bit.

 

Comments
Ceceil Rufo
Beginner

Hello:

Found an easier way to do this and not have to put a command wrapper around powershell.

  • Create a directory that is not in the windows directory path i.e. c:\powershell64 or x:\powershell64 (whatever works for your particular system).
  • Copy the powershell executable from the /windows/system32/powershell directory to your new directory.

Your tidal job will now look like this:

  • command line:  <new directory>\powershell.exe
    • example: c:\powershell64\powershell64.exe
      • I added the 64 to make it more understandable
  • parameter line: your script or whatever else you are calling.

 

Enjoy!   C. Rufo

Saleha101
Beginner

Hi Max,

 

I am trying to run Powershell Script from Tidal, Output printed to the OutPut tab but I want email output.

When I am placing the Action to send me attachment of the file, it is not working.

 

I am not running directly PowerShell.executable from Windows\System 32.  I copied the powershell.exe to my path 

command  E:\Powershell64\powershell.exe

parameter  -Executionpolicy -bypass -File E:\TidalPsScripts\GetCMSeclogs1.ps1

 

How I will txt the output to my email?  I attempt to trigger the Action with attachment but it is not working.

This is my command.

 

Content for Community-Ad