Skip to content

Instantly share code, notes, and snippets.

@pcgeek86
Last active December 20, 2021 17:36
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 pcgeek86/5a21ad3fe726ca25aa1f to your computer and use it in GitHub Desktop.
Save pcgeek86/5a21ad3fe726ca25aa1f to your computer and use it in GitHub Desktop.
Azure Disk Objects :: Add a StorageAccount property
<#
Author: Trevor Sullivan
Date: 2015-03-29
Description: Microsoft Azure Disk objects offer the full URL to the cloud-based VHD
however, the Storage Account name is not exposed independently. We can
use PowerShell's Add-Member command to parse the URL and offer up the
Storage Account as its own property on each Disk object.
#>
Select-AzureSubscription -SubscriptionName 'Visual Studio Ultimate with MSDN';
# Add a dynamic "StorageAccount" property to each Azure Disk object
$AddMember = @{
Name = 'StorageAccount';
MemberType = 'ScriptProperty';
Value = {
$null = $this.MediaLink -match 'https://(.*?)\.';
$matches[1];
};
PassThru = $true;
}
Get-AzureDisk | Add-Member @AddMember | Group-Object -Property StorageAccount;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment