title: PowerShell: AzureRM - Run Login-AzureRmAccount to login error
body: <p>I am trying to capture an image of an Azure VM I have created through my Azure account, as described in the Microsoft documentation: <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-capture-image" rel="nofollow noreferrer">How to capture a VM image from a generalized Azure VM</a>.</p>
  
  <p>I have successfully <a href="https://docs.microsoft.com/en-us/azure/virtual-machines/virtual-machines-windows-generalize-vhd?toc=%2Fazure%2Fvirtual-machines%2Fwindows%2Ftoc.json" rel="nofollow noreferrer">Generalized the VM</a> and then performed the login and subscription selection running the following commands in PowerShell (PSVersion 5.1.14393.953) with Admin rights:</p>
  
  <pre><code>Login-AzureRmAccount
  Get-AzureRmSubscription
  Select-AzureRmSubscription -SubscriptionId "my_subscription_id"
  </code></pre>
  
  <p>Next step is to stop (deallocate) the VM and set it to generalized, which can be done with following commands, still according to the documentation:</p>
  
  <pre><code>Stop-AzureRmVM -ResourceGroupName my-resource-group -Name my-vm-name
  Set-AzureRmVm -ResourceGroupName my-resource-group -Name my-vm-name -Generalized
  </code></pre>
  
  <p>However, both commands fail from PowerShell with a similar error. As I was able to stop (deallocate) the VM from <a href="http://portal.azure.com" rel="nofollow noreferrer">Azure Portal</a>, I am now trying to succeed on the Set-AzureRmVM call. Below is the error I am receiving from PowerShell:</p>
  
  <blockquote>
    <p>Set-AzureRmVM : Run Login-AzureRmAccount to login.
    At line:1 char:1
    + Set-AzureRmVM -ResourceGroupName configit-build -Name build-server -G ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (:) [Set-AzureRmVM], PSInvalidOperationException
        + FullyQualifiedErrorId : InvalidOperation,Microsoft.Azure.Commands.Compute.SetAzureVMCommand</p>
  </blockquote>
  
  <p>Any help is more than appreciated.
  Thanks.</p>