Running Powershell in Fixlet or Action Script

I am fairly new to Bigfix. I need to copy installation folder to C:\Program Files and then execute install-service-xxx.ps1. I would prefer to upload the files to BF and download them to C:\Program Files and execute the ps1. I am not sure how to do that. Here is the ps1 script I have tried to run unsuccessfully. I can execute on the device locally.

# Define source and destination paths
$sourceFolder = "\\xxxx\xxxx\xxx\xxxx\xxx"
$destinationFolder = "C:\Program Files\"
$scriptName = "install-service-xxxx.ps1"  # The name of the script to execute in the copied folder

# Ensure the destination folder exists
if (-Not (Test-Path -Path $destinationFolder)) {
    New-Item -ItemType Directory -Path $destinationFolder -Force
}

# Copy the folder and its contents
Copy-Item -Path $sourceFolder -Destination $destinationFolder -Recurse -Force

# Build the full path to the script in the copied folder
$scriptPath = Join-Path -Path "C:\Program Files\xxx" -ChildPath $scriptName

# Check if the script exists in the destination
if (Test-Path -Path $scriptPath) {
    # Execute the script with ExecutionPolicy Bypass
    Write-Host "Running script: $scriptPath"
    powershell.exe -ExecutionPolicy Bypass -File $scriptPath
} else {
    Write-Host "Script not found: $scriptPath"
}

xxx for masking actually file and folder location.

I also tried to deploying via a bat and I am still having an issue.

Any help would be greatly appreciated.

John

Have you tried using native PowerShell functionality to run your ps script?

image

Did you follow the best practices for escaping curly Brashes when you attempted to run a ps script using a batch file?

Escaping curly brackets in Action Script

There are many other forum posts around running ps script, you can also check them.

1 Like