[GH-ISSUE #1026] Add support for PowerShell Core 7.x on Windows and Linux #2574

Open
opened 2026-03-14 04:38:23 +03:00 by kerem · 10 comments
Owner

Originally created by @djsvi on GitHub (Mar 27, 2022).
Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/1026

I'd like the option within TRMM to natively run scripts using PowerShell Core 7.x on Windows and Linux endpoints.

There's some info about this here (for Windows) - https://docs.microsoft.com/en-us/powershell/scripting/whats-new/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7.2

I imagine a lot of TRMM users are far more comfortable with PowerShell than bash and suspect this might help grow the number of useful cross-platform scripts within the TRMM community.

Originally created by @djsvi on GitHub (Mar 27, 2022). Original GitHub issue: https://github.com/amidaware/tacticalrmm/issues/1026 I'd like the option within TRMM to natively run scripts using PowerShell Core 7.x on Windows and Linux endpoints. There's some info about this here (for Windows) - https://docs.microsoft.com/en-us/powershell/scripting/whats-new/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7.2 I imagine a lot of TRMM users are far more comfortable with PowerShell than bash and suspect this might help grow the number of useful cross-platform scripts within the TRMM community.
Author
Owner

@BMTTeam commented on GitHub (Mar 27, 2022):

"I imagine" - you imagine it wrong, but having move options is a good thing in the SysAdmin arsenal

Cheers,
-Tiho

<!-- gh-comment-id:1079889079 --> @BMTTeam commented on GitHub (Mar 27, 2022): "I imagine" - you imagine it wrong, but having move options is a good thing in the SysAdmin arsenal Cheers, -Tiho
Author
Owner

@dinger1986 commented on GitHub (Mar 27, 2022):

Totally agree with BMT.

Are you sure this isn't implemented? If a powershell script is set to all it will run on linux (or at least attempt to). Have you installed powershell on a linux server and tested?

<!-- gh-comment-id:1079910759 --> @dinger1986 commented on GitHub (Mar 27, 2022): Totally agree with BMT. Are you sure this isn't implemented? If a powershell script is set to all it will run on linux (or at least attempt to). Have you installed powershell on a linux server and tested?
Author
Owner

@djsvi commented on GitHub (Mar 28, 2022):

I haven't tested but if PowerShell Core support is already implemented for Linux that's great. That would just leave Windows which is otherwise stuck on 5.x.

<!-- gh-comment-id:1080131924 --> @djsvi commented on GitHub (Mar 28, 2022): I haven't tested but if PowerShell Core support is already implemented for Linux that's great. That would just leave Windows which is otherwise stuck on 5.x.
Author
Owner

@dinger1986 commented on GitHub (Mar 28, 2022):

Shall leave this open for you to test it and report back :)

<!-- gh-comment-id:1080295974 --> @dinger1986 commented on GitHub (Mar 28, 2022): Shall leave this open for you to test it and report back :)
Author
Owner

@silversword411 commented on GitHub (Mar 28, 2022):

Since TRMM is one huge scripting engine, this is probably something you can script on your own if you want to have powershell core on all the machines you want.

If you'd like to get any scripts you build for that purpose into the script library let me know and we'll get it done.

I'll close in a month if no movement.

<!-- gh-comment-id:1080580443 --> @silversword411 commented on GitHub (Mar 28, 2022): Since TRMM is one huge scripting engine, this is probably something you can script on your own if you want to have powershell core on all the machines you want. If you'd like to get any scripts you build for that purpose into the script library let me know and we'll get it done. I'll close in a month if no movement.
Author
Owner

@wh1te909 commented on GitHub (Mar 28, 2022):

something that might not be obvious...to use powershell on linux you'll actually need to choose "Shell" as the script type. then you will need to add a shebang as the first line of the script with the path to the powershell binary so like #!/usr/bin/env/powershell or wherever it is installed on your system

<!-- gh-comment-id:1080968393 --> @wh1te909 commented on GitHub (Mar 28, 2022): something that might not be obvious...to use powershell on linux you'll actually need to choose "Shell" as the script type. then you will need to add a shebang as the first line of the script with the path to the powershell binary so like `#!/usr/bin/env/powershell` or wherever it is installed on your system
Author
Owner

@djsvi commented on GitHub (Mar 29, 2022):

to use powershell on linux you'll actually need to choose "Shell" as the script type

(While appreciating Linux support is still beta) that's a bit kludgy :) Why not have TRMM natively run the powershell script using /opt/microsoft/powershell/pwsh ?

Then powershell scripts can all sit nicely side by side within TRMM.

<!-- gh-comment-id:1081747626 --> @djsvi commented on GitHub (Mar 29, 2022): > to use powershell on linux you'll actually need to choose "Shell" as the script type (While appreciating Linux support is still beta) that's a bit kludgy :) Why not have TRMM natively run the powershell script using /opt/microsoft/powershell/pwsh ? Then powershell scripts can all sit nicely side by side within TRMM.
Author
Owner

@silversword411 commented on GitHub (Mar 29, 2022):

Why not have TRMM natively run the powershell script using /opt/microsoft/powershell/pwsh

Because that's non-standard, now TRMM has to install and manage powershell core on linux, and detect OS to determine if it should be installed, and install PS Code on windows, and upgrade or repair, and regression test and and....

I'm sure most 'nix folks will not want powershell crufting up their 'nix install ;)

There's a workaround that you can fully implement for now if you want pshw. I'll leave it open, but I don't see much changing unless someone wants to pickup the ball and run with it.

<!-- gh-comment-id:1082384556 --> @silversword411 commented on GitHub (Mar 29, 2022): > Why not have TRMM natively run the powershell script using /opt/microsoft/powershell/pwsh Because that's non-standard, now TRMM has to install and manage powershell core on linux, and detect OS to determine if it should be installed, and install PS Code on windows, and upgrade or repair, and regression test and and.... I'm sure most 'nix folks will not want powershell crufting up their 'nix install ;) There's a workaround that you can fully implement for now if you want pshw. I'll leave it open, but I don't see much changing unless someone wants to pickup the ball and run with it.
Author
Owner

@P6g9YHK6 commented on GitHub (Mar 11, 2024):

having this on windows only would be nice.

no need to install it just puke an error out if the users try to use it and pwsh is not recognised.

<!-- gh-comment-id:1988719338 --> @P6g9YHK6 commented on GitHub (Mar 11, 2024): having this on windows only would be nice. no need to install it just puke an error out if the users try to use it and pwsh is not recognised.
Author
Owner

@P6g9YHK6 commented on GitHub (Mar 12, 2024):

Ok ended up doing a script to sort this out on windows:

It is set as a snippet "CallPowerShell7" and if {{CallPowerShell7}} is called the start of script it will run the whole thing as PowerShell 7

# Check for required PowerShell version (7+)
if (!($PSVersionTable.PSVersion.Major -ge 7)) {
  try {
    # Check if Chocolatey is installed
    if (!(Get-Command choco -ErrorAction SilentlyContinue)) {
        Write-Output 'Chocolatey is not installed. Installing Chocolatey...'
        # Install Chocolatey
        Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
        # Refresh PATH
        $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User')
        if (!(Get-Command choco -ErrorAction SilentlyContinue)) {
            Write-Output 'Chocolatey installation failed.'
            exit 1
        }
    }
    # Check if PowerShell 7 is installed
    if (!(Get-Command pwsh -ErrorAction SilentlyContinue)) {
        Write-Output 'PowerShell 7 is not installed. Installing PowerShell 7...'
        # Install PowerShell 7 using Chocolatey
        choco install powershell-core --install-arguments='"DISABLE_TELEMETRY"'-'"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1"'-'"ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1"'-'"REGISTER_MANIFEST=1"' -y
        if (!(Get-Command pwsh -ErrorAction SilentlyContinue)) {
            Write-Output 'PowerShell 7 installation failed.'
            exit 1
        }
    }
    # Refresh PATH
    $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User')
    # Restart script in PowerShell 7
    pwsh -File "`"$PSCommandPath`"" @PSBoundParameters
  }
  catch {
    Write-Output 'Error occurred while installing PowerShell 7.'
    throw $Error
    exit 1
  }
  finally { exit $LASTEXITCODE }
}

#Set the correct rendering for pwsh
$PSStyle.OutputRendering = "plaintext"
<!-- gh-comment-id:1991392738 --> @P6g9YHK6 commented on GitHub (Mar 12, 2024): Ok ended up doing a script to sort this out on windows: It is set as a snippet "CallPowerShell7" and if {{CallPowerShell7}} is called the start of script it will run the whole thing as PowerShell 7 ``` # Check for required PowerShell version (7+) if (!($PSVersionTable.PSVersion.Major -ge 7)) { try { # Check if Chocolatey is installed if (!(Get-Command choco -ErrorAction SilentlyContinue)) { Write-Output 'Chocolatey is not installed. Installing Chocolatey...' # Install Chocolatey Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1')) # Refresh PATH $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User') if (!(Get-Command choco -ErrorAction SilentlyContinue)) { Write-Output 'Chocolatey installation failed.' exit 1 } } # Check if PowerShell 7 is installed if (!(Get-Command pwsh -ErrorAction SilentlyContinue)) { Write-Output 'PowerShell 7 is not installed. Installing PowerShell 7...' # Install PowerShell 7 using Chocolatey choco install powershell-core --install-arguments='"DISABLE_TELEMETRY"'-'"ADD_FILE_CONTEXT_MENU_RUNPOWERSHELL=1"'-'"ADD_EXPLORER_CONTEXT_MENU_OPENPOWERSHELL=1"'-'"REGISTER_MANIFEST=1"' -y if (!(Get-Command pwsh -ErrorAction SilentlyContinue)) { Write-Output 'PowerShell 7 installation failed.' exit 1 } } # Refresh PATH $env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User') # Restart script in PowerShell 7 pwsh -File "`"$PSCommandPath`"" @PSBoundParameters } catch { Write-Output 'Error occurred while installing PowerShell 7.' throw $Error exit 1 } finally { exit $LASTEXITCODE } } #Set the correct rendering for pwsh $PSStyle.OutputRendering = "plaintext" ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tacticalrmm#2574
No description provided.