bolt
bolt copied to clipboard
Windows: Unable to run .ps1 task with pwsh.exe (powershell-core/powershell 7)
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
Did you try setting the interpreters for powershell implementations? https://www.puppet.com/docs/bolt/latest/bolt_transports_reference.html#interpreters-7
Hello,
Yes but that didn't seem to work. It appears that the powershell interpreters are hardcoded and cannot be changed.
I believe 'switch to pwsh' is a must-have feature. The old PS 5 is out-of-date now.
winrm accepts a argument '-ConfigurationName Powershell.7' to use PS7, but here are a lot of places hardcoded with powershell.exe