Manged Run command on Windows VM (SetAzVmRUnCommand) is deafulting to powershell 5.1
Description
I am trying to execute Powershell scripts using run commands on Windows VM. I have powershell 7 installed on the server. But Powershell 7 is not selected and it defaults to Powershell 5 while executing Run commands. Is it possible to select Powershell 7 for execution via run co mmands (Invoke Az VM run command/Set AzVM Run command)? I have tried creating a profile and mentioning pwsh.exe but I get error when I execute a Powershell via SetAzVMRun Command
Issue script & Debug output
Powershell script executed via https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command-managed
Environment data
Azure Windows VM server 2016
Module versions
Powershell 7
Error output
.
pwsh.exe : The term 'pwsh.exe' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1:3 char:1
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @Drewm3, @TravisCragg-MSFT, @nikhilpatel909, @sandeepraichura, @hilaryw29, @GabstaMSFT.
Issue Details
Description
I am trying to execute Powershell scripts using run commands on Windows VM. I have powershell 7 installed on the server. But Powershell 7 is not selected and it defaults to Powershell 5 while executing Run commands. Is it possible to select Powershell 7 for execution via run co mmands (Invoke Az VM run command/Set AzVM Run command)? I have tried creating a profile and mentioning pwsh.exe but I get error when I execute a Powershell via SetAzVMRun Command
Issue script & Debug output
Powershell script executed via https://learn.microsoft.com/en-us/azure/virtual-machines/windows/run-command-managed
Environment data
Azure Windows VM server 2016
Module versions
Powershell 7
Error output
.
pwsh.exe : The term 'pwsh.exe' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1:3 char:1
| Author: | Satyadm123 |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
@nikhilpatel909 can you have a look at this?
This will be a new feature request to Powershell team.
My bad, This is actually a feature request to run command so it will stay with me, We will evaluate and prioritize.
@Satyadm123 this is still on our roadmap and we are in internal discussions on this topic.
@Satyadm123 we are testing a change and expect to be releasing an update once testing is completed.
Get @GabstaMSFT, any update on this? It selecting 5.1 is causing some issue for me as I need some features that are only available in PowerShell Core
@AlexanderSehr we have started rolling out the change to Azure, once the rollout is complete I will update here. I anticipate it will be completed by the end of the month.
@AlexanderSehr we have started rolling out the change to Azure, once the rollout is complete I will update here. I anticipate it will be completed by the end of the month.
@GabstaMSFT any update on this? (we are on West-Europe)
The rollout has completed and this issue should be resolved.
@GabstaMSFT is there any documentation on how to use PowerShell 7 with managed run commands?
- I only found this one: Using Powershell7 with Managed Runcommand using a scriptShell parameter in an ARM template.
- How can this be achieved via PowerShell Set-AzVMRunCommand (Module Az.Compute) or New-AzConnectedMachineRunCommand (Module Az.ConnectedMachine) cmdlet?
- How to use PowerShell 7 with managed run command REST API? Virtual Machine Run Commands - Create Or Update for virtual machines and Machine Run Commands - Create Or Update for Arc-enabled servers.
Hi @klamir051 ,
- Set-AzVMRunCommand cmdlet does not have the "scriptShell" parameter yet. We will raise a request with Powershell team to include that.
- REST API specs should reflect "ScriptShell" in few months. A change has been made for that and public docs need to be published yet. How to use: Just add another property called scriptShell under properties, parallel to source "properties": { "source": { "script": "Write-Host HelloWorld" }, "scriptShell" : "Powershell7" }
Hi, we're sending this friendly reminder because we haven't heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!