Skip to content

Instantly share code, notes, and snippets.

@AbhiOnGithub
Created July 30, 2018 10:56
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 AbhiOnGithub/4d582bbaf175fa97bba04db809e107cf to your computer and use it in GitHub Desktop.
Save AbhiOnGithub/4d582bbaf175fa97bba04db809e107cf to your computer and use it in GitHub Desktop.
<#
.DESCRIPTION
An example runbook which gets all the ARM resources using the Run As Account (Service Principal)
.NOTES
AUTHOR: Azure Automation Team
LASTEDIT: Mar 14, 2016
#>
$connectionName = "AzureRunAsConnection"
try
{
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection=Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
}
catch {
if (!$servicePrincipalConnection)
{
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
}
}
#Get all ARM resources from all resource groups
$ResourceGroups = Get-AzureRmResourceGroup
foreach ($ResourceGroup in $ResourceGroups)
{
Write-Output ("Showing resources in resource group " + $ResourceGroup.ResourceGroupName)
$Resources = Find-AzureRmResource -ResourceGroupNameContains $ResourceGroup.ResourceGroupName | Select ResourceName, ResourceType
ForEach ($Resource in $Resources)
{
Write-Output ($Resource.ResourceName + " of type " + $Resource.ResourceType)
}
Write-Output ("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment