Jump to content

Unable to use "param" with Powershell Scripts


Tyler Melville

Recommended Posts

Up until the most recent update to Pulseway, I was able to install the Huntress agent via their provided Powershell script at: https://github.com/huntresslabs/deployment-scripts/blob/main/Powershell/InstallHuntress.powershellv2.ps1

This script includes the "param" command, which has to be the first line of the script in order to run. 

After the recent update to Pulseway, all scripts that are run add an $ENV_AgentTemp variable to the top of the script, see screenshot below:
PastedGraphic1.thumb.png.57cf7104efe98d6d7624bcfcc59b537e.png

This prevents the script from running correctly, see screenshot below of the error:
PastedGraphic.png.b8423716bb785b176d22c5dfbd3c79ac.png

 

Please note that the powershell output shows the error on line 32, whereas in the script it is on line 31, which is what led me on the path to find that the extra line was being added at the top of the script by Pulseway. 

Is there a way to prevent that first line from being added to the script, or do I need to contact Huntress and have them rework a different version of the script that doesn't include the "param" command?

Cheers.

Link to comment
Share on other sites

You are using parameters outside of a function. Parameters can only be defined inside of a function, otherwise you are essentially trying to run the 'param' command.

For example:

image.thumb.png.cb3a18ec6c57610bf06a989051d7b6ea.pngimage.png.731170d15bc9c1e24d520e9807626389.png

Edited by Brandonn
Photos did not come through
Link to comment
Share on other sites

On 4/22/2023 at 12:57 AM, Brandonn said:

You are using parameters outside of a function. Parameters can only be defined inside of a function, otherwise you are essentially trying to run the 'param' command.

For example:

image.png.cf34e42c148428d81ae7d6a39bac77a4.pngimage.png.99e9b297a4b346484385fa8104b463f5.png

Hi.

Can you repost your images I can not see them. 

Thanks,

Richard

Link to comment
Share on other sites

On 4/25/2023 at 11:12 AM, Richard Davis said:

Hi.

Can you repost your images I can not see them. 

Thanks,

Richard

They should be there now.

Maybe wrap the huntress install script in a function that passes all the relevant information?

I did some more testing, and you can include the arguments if you are just running the script normally, but since you cannot include additional arguments when running the script through Pulseway, they will have to be manually added to the script.

I believe this would work.

function Install-Huntress {

	param (
		[string]$acctkey,
		[string]$orgkey,
		[string]$tags,
		[switch]$reregister,
		[switch]$reinstall,
		[switch]$uninstall,
		[switch]$repair
	)


# Rest of the code
return "$acctkey - $orgkey - $tags - $reregister - $reinstall - $uninstall - $repair"
}

Install-Huntress -acctkey 1234 -orgkey 5678 -tags "tag1" -reregister $true -uninstall $false -repair $false

 

Edited by Brandonn
Fixed Script
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...