0
votes

Using Visual Studio 2017,

  • I created a new Azure Resource Group Deployment project from template.
  • I replaced the content of the parameters and template file with ones I had already generated from another resource group that I had manually created.
  • I right clicked on the project and deployed.
  • I discovered that the resources deployed to another subscription of mine that was not selected in the drop-down menu.
  • While trying to discover how it was selecting the target subscription, I copied the generated powershell deployment script, parameters and template file to another folder that did not have the visual studio project in it.
  • I ran the powershell script, and the resources deployed as before without requiring any credentials of mine.

I believe that visual studio has stored my credentials and deployment settings somewhere, but I can't discover where. I suspect it's some fixed location that's known by powershell because the script works from any directory on my system, but I haven't been able to discover any information about where that might be.

How am I able to run this script from anywhere, and where is the magic file that has my creds in it (if it exists)?

2

2 Answers

1
votes

If you start a Powershell somewhere and try running get-azureAccount or Get-AzureRmAccount if it returns results of your Azure credentials then it indicates PowerShell contains your account login in the cache.

Run this to remove the cached credentials.

 Get-AzureAccount | ForEach-Object { Remove-AzureAccount $_.ID -Force }

After running the command, all of your cached credentials will be removed and your system will be clean. Cheers! I have done the same thing previously when my pc went rogue with someone else's credentials.

1
votes

I needed to clear powershell's Azure Resource Manager Context, which it had cached.

Clear-AzureRmContext -Scope CurrentUser

(Thanks to HariHaran for pointing me in the right direction.)