Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Powershell: What is the opposite command to Login-AzureRmAccount (used to be Clear-AzureProfile)

I have various scripts which I used to run in a wrapper to allow me to handle things like checking I had a valid connection and to ask the user if the connection/subscription currently selected is the one they want to run the script on before running it etc.

The classic commands have Clear-AzureProfile which allows me to run it from a script and effectively break the connection so that it can't be used again without calling Add-AzureAccount.

With the RM cmdlets I can only find Login-AzureRmAccount but once I've logged in...how do I call logout?

There doesn't appear to be a Logout-AzureRMAccount or Remove-AzureRMAccount and Clear-AzureProfile has no effect.

I run a dev workstation and connect to several different client subscriptions so want to be able to destroy the connection rather than just calling another login over the top of it (if that login failed I would still have the old connection set up which is dangerous for me)

I've just logged this at: https://msdn.microsoft.com/en-us/library/mt619248.aspx as from the documentation it looks like the commands may be lacking

like image 584
Dave Hodgson Avatar asked Dec 09 '15 14:12

Dave Hodgson


2 Answers

It appears the following works:

Set-AzureRmContext -Context ([Microsoft.Azure.Commands.Profile.Models.PSAzureContext]::new())
like image 143
charleswj81 Avatar answered Sep 24 '22 02:09

charleswj81


UPDATE: For new powershell Azure "az" module, please use

Connect-AzAccount

for login and

Disconnect-AzAccount

for logout.

like image 36
Tomino Avatar answered Sep 23 '22 02:09

Tomino