puppetlabs / bolt

Bolt is an open source orchestration tool that automates the manual work it takes to maintain your infrastructure on an as-needed basis or as part of a greater orchestration workflow. It can be installed on your local workstation and connects directly to remote nodes with SSH or WinRM, so you are not required to install any agent software.
https://puppet.com/docs/bolt/latest/bolt.html
Apache License 2.0
500 stars 225 forks source link

Windows: Unable to run .ps1 task with pwsh.exe (powershell-core/powershell 7) #3254

Open TraGicCode opened 11 months ago

TraGicCode commented 11 months ago

I have the following powershell task:

Import-Module Particular.ServiceControl.Management  4>$null

$result = @()

$errorInstances = Get-ServiceControlInstances
foreach($instance in $errorInstances)
{
    $result += [PSCustomObject] @{
        Name        = $instance.Name
        InstallPath = $instance.InstallPath
        DBPath      = $instance.DBPath
        ExecutablePath = Join-Path -Path $instance.InstallPath -ChildPath "ServiceControl.exe"
        Type = 'error'
    }
}

$auditInstances = Get-ServiceControlAuditInstances
foreach($instance in $auditInstances)
{
    $result += [PSCustomObject] @{
        Name        = $instance.Name
        InstallPath = $instance.InstallPath
        DBPath      = $instance.DBPath
        ExecutablePath = Join-Path -Path $instance.InstallPath -ChildPath "ServiceControl.Audit.exe"
        Type = 'audit'
    }
}

$monitoringInstances = Get-MonitoringInstances
foreach($instance in $monitoringInstances)
{
    $result += [PSCustomObject] @{
        Name        = $instance.Name
        InstallPath = $instance.InstallPath
        ExecutablePath = Join-Path -Path $instance.InstallPath -ChildPath "ServiceControl.Monitoring.exe"
        Type = 'monitor'
    }
}

ConvertTo-Json -InputObject @{"_items" = $result} -Compress 

The Particular.ServiceControl.Management powershell module ONLY works on pwsh.exe (powershell-core/powershell 7). How can i get bolt to use pwsh.exe instead of powershell.exe (v5) when running the following command.

bolt task run nservicebusservicecontrol::get_instances --targets localhost

https://forge.puppet.com/modules/tragiccode/nservicebusservicecontrol

donoghuc commented 10 months ago

Did you try setting the interpreters for powershell implementations? https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html#interpreters-7

TraGicCode commented 8 months ago

Hello,

Yes but that didn't seem to work. It appears that the powershell interpreters are hardcoded and cannot be changed.

HoytRen commented 4 months ago

I believe 'switch to pwsh' is a must-have feature. The old PS 5 is out-of-date now.

HoytRen commented 4 months ago

winrm accepts a argument '-ConfigurationName Powershell.7' to use PS7, but here are a lot of places hardcoded with powershell.exe