How to Store Azure Credential in Azure VM?

Hi,

Is there any way I can store my Microsoft Azure credential in Azure Virtual Machine. We have one custom software which runs some programming work and shut down the computer automatically.

We have one batch file in place which shut down the local computer as azure is different which needs to be deallocated after shutting down the VM.

Using the below command I am able to deallocate the VM but It ask for the credential since I am the only one Authorized to access the Azure portal I cannot share my credentail. So, I am looking for a way to save my Microsoft Azure credential in a secure way which doesn’t compromise my credential

Thanks

1 Like

Which command are you using to deallocate the VM?
Are you sure you want to do that or just shut it down?

1 Like

Sorry, I missed to add the PowerShell command for deallocation.

Stop-AzureRmVM -ResourceGroupName "ResourceGroupName" -Name "VirtualMachineName" -force

The above command shutdown the VM and Deallocation all the allocated hardware.

1 Like

Hi @HabibAhmed,

You need to use Save-AzureRmContext command to save your credential in the local system.

For example:

Connect-AzureRmAccount
PS C:\> Save-AzureRmContext -Path C:\test.json

This will save the credential in .json file.

Note: After saving the credential if you didn’t use it for a long time 30 days it will automatically expires you need to run the command again.

2 Likes

Thanks @tjnihal,

It’s working as expected… :grinning:

1 Like