Az-Connect on a Windows Server
Hello!
I recently had to create a VM in Azure that was in the same region as a Data Lake I was working on as the network delay in running some Az PowerShell cmdlets from my laptop here in the UK was causing some issues.
Logging in should be simple enough -
if ($null -eq (Get-AzContext)){
Write-Host "No Azure Context... logging in. Check for login window behind this one, especially if you are using VSCode!"
Login-AzAccount
}
However even with Enhanced Security Configuration being disabled, the login window just would not work properly. So what to do? Thankfully, there is a switch called UseDeviceAuthentication
that gives a url and a code to enter to sign in.
if ($null -eq (Get-AzContext)){
Write-Host "No Azure Context... logging in..."
Login-AzAccount -UseDeviceAuthentication
}
The neat thing about this option is that the code and web page do not have to be used on the VM, so I was able to run it on my laptop and still get authenticated on the VM.