Azure / Azure/azure-powershell

Azure Authenticate

Open
#29,335 2 comments 0 reactions 1 assignee Claimed by @isra-fel View on GitHub
act-identity-squad bug customer-reported
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
3d 14h
Merged PRs (30d)
54

Description

### Description

Ok I have some or azure code which basically just gets hardware inventory if machines in Azure. I wrote the code first on my test machine at home. Here is the code
See below

The first line you have to log into your azure account again even though you are already logged into Azure. It asked you to
Login to Azure] To sign in, use a web browser to open the page https://login.microsoft.com/device and enter the code to authenticate.
When I enter the code to authenticate,on my home machine it immediately said you are logging into Azure from another machine and it ask to confirm your email address once you confirm it ask you to close the browser and it the code runs perfectly. However on my work azure account I do the exact same thing however when I put in my email address it saiyes it doesnt recognise it. As a result my code doesnt run

### Issue script & Debug output

```PowerShell
Connect-AzAccount -UseDeviceAuthentication

$report = @()
$vms = Get-AzVM | Where-Object { $_.StorageProfile.OsDisk.OsType -eq "Windows" }

foreach ($vm in $vms) {
$sizeDetails = Get-AzVMSize -ResourceGroupName $vm.ResourceGroupName -VMName $vm.Name |
Where-Object { $_.Name -eq $vm.HardwareProfile.VmSize } |
Select-Object -First 1

$info = [PSCustomObject]@{
VMName = $vm.Name
ResourceGroupName = $vm.ResourceGroupName
Location = $vm.Location
VmSize = $vm.HardwareProfile.VmSize
CPUCores = $sizeDetails.NumberOfCores
MemoryGB = [math]::Round($sizeDetails.MemoryInMB / 1024, 2)
OsType = $vm.StorageProfile.OsDisk.OsType
ProvisioningState = $vm.ProvisioningState
}

$report += $info
}

$csvPath = "$HOME/AzureWindowsInventory.csv"
$report | Export-Csv -Path $csvPath -NoTypeInformation

Write-Host "Inventory exported to $csvPath" -ForegroundColor Green
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.5.4
PSEdition Core
GitCommitId 7.5.4
OS Microsoft Azure Linux 3.0
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
module versions

ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 5.3.2 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 11.2.0 Az.Compute {Add-AzGalleryInVMAccessControlProfileVersionRulesIdentity, Add-AzGalleryInVMAccessControlProfileVersionRulesPrivilege, Add-AzGalleryInVMAccessControlProfileVersionR…
Script 7.24.1 Az.Network {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGatewayBackendHttpSetting, Add-AzApplicationGatewayB…
Script 9.0.0 Az.Resources {Export-AzResourceGroup, Export-AzTemplateSpec, Get-AzDenyAssignment, Get-AzDeployment…}
Script 9.5.0 Az.Storage {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountManagementPolicyAction, Add-AzStorageAccountNetworkRule, Close-AzStorageFileHandle…}
Script 1.1.3 Az.Tools.Predictor {Disable-AzPredictor, Enable-AzPredictor, Open-AzPredictorSurvey, Send-AzPredictorRating}
Script 0.0.0.10 AzureAD.Standard.Preview {Add-AzureADApplicationOwner, Add-AzureADDeviceRegisteredOwner, Add-AzureADDeviceRegisteredUser, Add-AzureADDirectoryRoleMember…}
Script 0.9.3 AzurePSDrive
```

### Error output

```PowerShell
I cant run it because I cannot log into azure again. Like what I can do on my home machine
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.