Created
July 30, 2018 10:56
-
-
Save AbhiOnGithub/4d582bbaf175fa97bba04db809e107cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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