Azure-Samples / iotedge-logging-and-monitoring-solution

IoT Edge Logging and Monitoring Solution (ELMS) is an architecture and sample cloud workflow that enables automated retrieval of logs and metrics from IoT Edge devices
MIT License
42 stars 22 forks source link

Script fails on mixing cli with powershell commands #4

Closed dc995 closed 2 years ago

dc995 commented 2 years ago

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Attempt tp run the script. It fails under powershell 7 and runs under Powershell 5.1.22000.65

Any log messages given by the failure

ERROR: AADSTS700082: The refresh token has expired due to inactivity. The token was issued on 2021-03-02T18:40:35.2776433Z and was inactive for 90.00:00:00. Trace ID: 8bc2c1db-3176-485e-961b-de2800cb3d01 Correlation ID: cedce3c5-a206-4ea4-882c-13e817f24086 Timestamp: 2021-10-11 23:47:30Z To re-authenticate, please run az login. If the problem persists, please contact your tenant administrator.

Expected/desired behavior

supposed to be able to select from resources - each time this goes to the az cli, it blows up with errors. Choose a location for your deployment from this list (using its Index):

:

Choose from the list using an index between 1 and 0.

: 1

Choose from the list using an index between 1 and 0.

:

If I modify the script like so to use powershell then it works properly but the cli piping is all over this script

    $script:resource_group_name = Read-Host -Prompt ">"
    $resourceGroup=Get-AzResourceGroup -Name $script:resource_group_name -ErrorAction SilentlyContinue
    # Fails to follow authz context
    # $resourceGroup = az group list | ConvertFrom-Json | Where-Object { $_.name -eq $script:resource_group_name }
    if (!$resourceGroup.ResourceGroupName -eq $script:resource_group_name) {
        $script:create_resource_group = $true
    }
    else {
        $script:create_resource_group = $false
    }
}

}

OS and Version?

Windows 7, 8 or 10. Linux (which distribution). macOS (Yosemite? El Capitan? Sierra?) Windows 11 - running under Terminal with 2 versions of powershell

Versions

Mention any other details that might be useful

I tried to use "az account set --subscription mysubscriptionname" to see if I could focus it on my target sub while debugging in vscode but that didnt work.


Thanks! We'll be in touch soon.

marvin-garcia commented 2 years ago

@dc995 have you tried to run az login on PowerShell 7 before running the wizard? Access tokens may not be shared across different PS versions.

dc995 commented 2 years ago

Thanks, it is working properly under powershell 7