-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invoke-AzContainerInstanceCommand output #15754
Comments
Thanks for reporting. The current cmdlet is following its API definition. We will consider to provide additional logic. |
Thanks - that would have been great. Per now, the command is not useful for the regular IT Pro/PowerShell Admin the way I see it. |
Hi @janegilring , I'm sorry we have to postpone the onboard of additional logic since this command should not just work as Send/Receive mode, it would work as an interactive way by web socket like:
So that we needs more time to do additional investigation and we will go back to you when we find a proper solution. |
Hi @BethanyZhou, could you please share how can we implementing the WebSocketUri and password to get the result? Looks like the Invoke-AzContainerInstanceCommand didn't executed any command on the container? For example, to create a test file, we ran this line on azure cloud shell But in the container instance, nothing happened if I ran the azcli version on my local computer (with azure-cli at 2.27, 2.28 has some breaking change) |
Hi @amarkwong , Yes, we need send password to its corresponding websocket to trigger command execution. That's why Invoke-AzContainerInstanceCommand didn't executed any command on the container.
A rough code for non-interactive command is as below: # $response is the execution result of current Invoke-AzContainerInstanceCommand
$socket = [System.Net.WebSockets.ClientWebSocket]::new()
$uri = [System.Uri]::new($response.WebSocketUri)
$cts = [System.Threading.CancellationTokenSource]::new()
$socket.ConnectAsync($uri, $cts.Token).Wait()
$bytesToSend = New-Object System.ArraySegment[byte] -ArgumentList @(,[System.Text.Encoding]::UTF8.GetBytes($response.Password))
$conn = $socket.SendAsync($bytesToSend, [System.Net.WebSockets.WebSocketMessageType]::Text, $true, $cts.Token).Wait()
$allBytes = New-Object System.Collections.Generic.List[byte]
while($socket.State -eq [System.Net.WebSockets.WebSocketState]::Open)
{
$bytesReceived = New-Object System.ArraySegment[byte] -ArgumentList @(, (new-object byte[] 1024))
$result = $socket.ReceiveAsync($bytesReceived, [System.Threading.CancellationToken]::None).GetAwaiter().GetResult()
$allBytes.AddRange($bytesReceived.Slice(0, $result.Count))
}
return [System.Text.Encoding]::UTF8.GetString($allBytes.ToArray(), 0, $allBytes.Count) We are planning return command execution result in |
link PR #16350 |
Close as #16518 closed. Following new features in |
Hi @BethanyZhou has this been released yet? I am still having the same issue as @amarkwong Currently the command |
Hi @obayesshelton , this enhancement had been enabled in Az.ContainerInstance>=3.0.0. Pleas check your module version. |
Hi, Two comments about the Invoke-AzContainerInstanceCommand cmdlet in Az.ContainerInstance>=3.0.0 :
|
Hi @otabut , Thanks for reporting.
You can obtain last execution result by Invoke-AzContainerInstanceCommand -PassThru
Could you provide example for this case? |
Thanks for quick response.
|
I'm still only able to get this command working if i use powershell 7 and run all the code suggested by @BethanyZhou |
@BenH-Puregym , please upgrade Az.ContainerInstance to latest version, Invoke-AzContainerInstanceCommand returns command execution result now. |
Description
Scenario: Execute a command within an Azure Container Instances container.
By using Azure CLI, this works as expected:
When trying to accomplish the same using Azure PowerShell, the output is not the command output - but rather a password and a websocket URI as shown below. Could it be that the Azure CLI uses these credentials to actually gather the command output, but the PowerShell command does not? If so, it would be useful if this behaviour could be change similarly to Azure CLI.
Also, it is unclear why we in the PowerShell command need to specify -TerminalSizeCol and -TerminalSizeRow, while in the Azure CLI option we do not.
Steps to reproduce
Environment data
Module versions
Debug output
Error output
The text was updated successfully, but these errors were encountered: