Created
March 10, 2014 09:40
-
-
Save tomconte/9462098 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Parameters | |
| #$publishSettingFilePath = "C:\Users\tconte\Downloads\Hermes-Recette-11-21-2013-credentials.publishsettings" | |
| $publishSettingFilePath = "C:\Users\tconte\Downloads\Windows Azure BizSpark 1111-JeromeSAS-4-19-2013-credentials.publishsettings" | |
| #$subscriptionName = "Hermes-Recette" | |
| $subscriptionName = "Windows Azure BizSpark 1111" | |
| $outfiledisks="C:\dev\result_disks.txt" | |
| $outfilefiles="C:\dev\results_files.txt" | |
| $outfilenetworks="C:\dev\results_network.txt" | |
| $outfileendpoints="C:\dev\results_endpoints.txt" | |
| $outfilevms="C:\dev\results_vms.txt" | |
| # Import the PowerShell module for Windows Azure (http://www.windowsazure.com/en-us/manage/install-and-configure-windows-powershell) | |
| Import-Module azure | |
| # Dowload the Publish Settings file if required | |
| #Get-AzurePublishSettingsFile | |
| # Import the Publish Settings | |
| Import-AzurePublishSettingsFile $publishSettingFilePath | |
| # Select the subscription to use | |
| Set-AzureSubscription -SubscriptionName $subscriptionName | |
| Select-AzureSubscription -SubscriptionName $subscriptionName | |
| Write-Output "Working..." | |
| $null > $outfilenetworks | |
| $null > $outfiledisks | |
| $null > $outfileendpoints | |
| $null > $outfilevms | |
| $null > $outfilefiles | |
| ### Enumerate Virtual Machines and output configuration details ### | |
| Get-AzureVM | ForEach-Object { | |
| $VM = Get-AzureVM -ServiceName $_.ServiceName -Name $_.Name | |
| # VM details | |
| Write-Output ($VM.Name + ";" + $VM.ServiceName + ";" + $VM.IpAddress + ";" + $VM.InstanceSize + ";" + $VM.PowerState) >> $outfilevms | |
| # Endpoints | |
| $endpoints = Get-AzureEndpoint -VM $VM | |
| if ($endpoints -eq $null) | |
| { | |
| Write-Output ($VM.Name + ";;;;;") >> $outfileendpoints | |
| } | |
| else | |
| { | |
| $endpoints | ForEach-Object { | |
| $endpoint = $_ | |
| Write-Output ($VM.Name + ";" + $VM.ServiceName + ";" + $endpoint.Name + ";" + $endpoint.Port + ";" + $endpoint.Protocol + ";" + $endpoint.Acl) >> $outfileendpoints | |
| } | |
| } | |
| # Subnets | |
| $subnets = Get-AzureSubnet -VM $VM | |
| if ($subnets -eq $null) | |
| { | |
| Write-Output ($VM.Name + ";") >> $outfilenetworks | |
| } | |
| else | |
| { | |
| $subnets | ForEach-Object { | |
| $subnet = $_ | |
| Write-Output ($VM.Name + ";" + $subnet) >> $outfilenetworks | |
| } | |
| } | |
| # Disks | |
| $OSDisk = $VM | Get-AzureOSDisk | |
| Write-Output ($VM.Name + ";" + $OSDisk.DiskName + ";" + $OSDisk.MediaLink.AbsoluteUri) >> $outfiledisks | |
| # List every data disk for that VM | |
| $VM | Get-AzureDataDisk | ForEach-Object { | |
| Write-Output ($VM.Name + ";" + $_.DiskName + ";" + $_.MediaLink.AbsoluteUri) >> $outfiledisks | |
| } | |
| } | |
| # List orphaned data disks | |
| Get-AzureDisk | Where-Object {$_.AttachedTo -eq $null} | ForEach-Object { | |
| Write-Output (";;" + $_.DiskName + ";" + $_.MediaLink.AbsoluteUri) >> $outfiledisques | |
| } | |
| ### Liste des fichiers ### | |
| #Pour chaque storage account | |
| Get-AzureStorageAccount | ForEach-Object { | |
| $storageAccount = $_ | |
| $storageAccountKey = (Get-AzureStorageKey $storageAccount.StorageAccountName).Primary | |
| $storageContext = New-AzureStorageContext -StorageAccountName $storageAccount.StorageAccountName -StorageAccountKey $storageAccountKey | |
| #Pour chaque container de ce storage account | |
| Get-AzureStorageContainer -Context $storageContext | ForEach-Object { | |
| $container = $_ | |
| #Pour chaque fichier de ce container | |
| Get-AzureStorageBlob -Container $container.Name -Context $storageContext | ForEach-Object { | |
| $blob = $_ | |
| Write-Output ($storageAccount.StorageAccountName + ";" + $container.Name + ";" + $blob.Name + ";" + $blob.ICloudBlob.Properties.LeaseDuration) >> $outfilefiles | |
| } | |
| } | |
| } | |
| Write-Host "Finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment