bolt icon indicating copy to clipboard operation
bolt copied to clipboard

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

Open TraGicCode opened this issue 1 year ago • 4 comments

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

TraGicCode avatar Dec 14 '23 10:12 TraGicCode

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

donoghuc avatar Jan 02 '24 19:01 donoghuc

Hello,

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

TraGicCode avatar Mar 11 '24 07:03 TraGicCode

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

HoytRen avatar Jul 11 '24 09:07 HoytRen

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

HoytRen avatar Jul 12 '24 08:07 HoytRen