Az PowerShell Module

Install-Module Az
  1. Connecting

Connect-AzAccount

$passwd = ConvertTo-SecureString "V3ryH4rdt0Cr4ckN0OneCanGu3ssP@ssw0rd" -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential("test@defcorphq.onmicrosoft.com",$passwd)
Connect-AzAccount -Credential $creds
  1. Searching for commands

Get-Command *azad*
Get-Command *az*
Get-Command *azvm*

Basics

  • Get the information about the current context (Account, Tenant, Subscription etc.)

Get-AzContext
  • List all available contexts

Get-AzContext -ListAvailable

If we enumerate we can use Set-AzContext -Context <Active Context>

  • Enumerate subscriptions accessible by the current user

Get-AzSubscription
  • Enumerate all resources visible to the current user

Get-AzResource
  • Enumerate all Azure RBAC role assignments

Get-AzRoleAssignment
  • Virtual Machines

 Get-AzVM
  • App Services

Get-AzWebApp | Select-Object ResourceGroup, Name, Location, State
  • Function Apps

Get-AzWebApp | Select-Object ResourceGroup, Name, Kind, Location, State
  • Storage Accounts

Get-AzStorageAccount | fl *
  • Key Vaults

Get-AzKeyVault | fl *

Users

  • Enumerate all users

Get-AzADUser
  • Enumerate a specific user

Get-AzADUser -UserPrincipalName test@defcorphq.onmicrosoft.com
  • Search for a user based on string in first characters of DisplayName (wildcard not supported)

Get-AzADUser -SearchString "admin"
  • Search for users who contain the word "admin" in their Display name:

Get-AzADUser |?{$_.Displayname -match "admin"}

Groups

  • List all groups

Get-AzADGroup 
  • Enumerate a specific group

Get-AzADGroup -ObjectId 783a312d-0de2-4490-92e4-539b0e4ee03e
  • Search for a group based on string in first characters of DisplayName (wildcard not supported)

Get-AzADGroup -SearchString "admin" | fl *
  • To search for groups which contain the word "admin" in their name:

Get-AzADGroup |?{$_.Displayname -match "admin"}
  • Get members of a group

Get-AzADGroupMember -ObjectId 783a312d-0de2-4490-92e4-539b0e4ee03e

Apps

  • Get all the application objects registered with the current tenant (visible in App Registrations in Azure portal). An application object is the global representation of an app.

Get-AzADApplication
  • Get all details about an application

Get-AzADApplication -ObjectId a1333e88-1278-41bf-8145-155a069ebed0
  • Get an application based on the display name

Get-AzADApplication | ?{$_*.*DisplayName -match "app"}
  • The Get-AzADAppCredential will show the applications with an application password but password value is not shown. List all the apps with an application password.

Get-AzADApplication | %{if(Get-AzADAppCredential -ObjectID $_.ID){$_}}

Service Principals

  • Enumerate Service Principals (visible as Enterprise Applications in Azure Portal). Service principal is local representation for an app in a specific tenant and it is the security object that has privileges. This is the 'service account'!

  • Service Principals can be assigned Azure roles.

  • Get all service principals

Get-AzADServicePrincipal 
  • Get all details about a service principal

Get-AzADServicePrincipal -ObjectId cdddd16e-2611-4442-8f45-053e7c37a264
  • Get a service principal based on the display name

Get-AzADServicePrincipal | ?{$_.DisplayName -match "app"}

Last updated