Skip to content

Instantly share code, notes, and snippets.

@sharepointoscar
Last active March 2, 2018 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharepointoscar/8d0db4f9da4962d8723191b7316c0720 to your computer and use it in GitHub Desktop.
Save sharepointoscar/8d0db4f9da4962d8723191b7316c0720 to your computer and use it in GitHub Desktop.
Login to Azure via PowerShell non-interactive
# Install required module
Install AzureRM Module
# Load Module
Import AzureRM Module
# Create a Credential Object
$clientID = <CLIENT_ID>
$key = <CLIENT_SECRET>
$SecurePassword = $key | ConvertTo-SecureString -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $clientID, $SecurePassword
# login non-interactive
Login-AzureRmAccount -Credential $cred -ServicePrincipal -TenantId
# query azure
Get-AzureRmVM -ResourceGroupName "spfarmstaging" | Select-Object name,ResourceGroupName | Where {$_.name -ne "SP2012R2AD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment