[英]Get storage account of Azure VM
I am trying to find PowerShell cmdlet which can retrieve information about which storage account Azure VM use. 我正在尝试查找PowerShell cmdlet,它可以检索有关Azure VM使用的存储帐户的信息。 Example, I want to supply name of VM and I would like to see which storage that VM use.
例如,我想提供VM的名称,我想看看VM使用哪个存储。 Or it will be also good to query specific storage account and see which VMs use this storage account.
或者,查询特定存储帐户并查看哪些VM使用此存储帐户也很有用。
I am trying following cmdlets but I cannot see details about storage account: 我正在尝试关注cmdlet,但我看不到有关存储帐户的详细信息:
Select-AzureSubscription -SubscriptionName "name"
Get-AzureVM -Name "name" -ServiceName "name"
The Get-AzureDisk cmdlet may be useful for you. Get-AzureDisk cmdlet可能对您有用。 This is the approach that I'm using.
这是我正在使用的方法。
$disk = Get-AzureDisk | Where-Object { $_.AttachedTo.RoleName -eq "YOURVMNAME" }
$mediaLink = $disk.MediaLink
$storageAccountName = $mediaLink.Host.Split('.')[0]
https://msdn.microsoft.com/en-us/library/azure/dn495125.aspx https://msdn.microsoft.com/en-us/library/azure/dn495125.aspx
I am answering the second part of your question. 我正在回答你问题的第二部分。 You want list of VM under a particular Storage Account.
您需要特定存储帐户下的VM列表。 Suppose your storage account name is "xyz123" and you want to list all vms under this storage account.
假设您的存储帐户名称为“xyz123”,并且您要列出此存储帐户下的所有虚拟机。 Then you just need to run the script given below-
然后你只需要运行下面给出的脚本 -
$vms = Get-AzureVM
$output = " "
$tgtStorageaccount = "xyz123"
foreach($vm in $vms)
{
$disk = Get-AzureVM -ServiceName $vm.ServiceName –Name $vm.Name | Get-AzureOSDisk
$mediaLink = $disk.MediaLink
$storageAccountName = $mediaLink.Host.Split('.')[0]
if ($storageAccountName -eq $tgtStorageaccount)
{
$output =$output + "`r`n" + $vm.Name
}
}
$output
Hope This one will help you. 希望这个会帮助你。 Thanks.
谢谢。
Yes. 是。
Storageaccount
can be find for RM based VM. 可以为基于RM的VM找到
Storageaccount
。
For OS: 对于OS:
$output = Get-AzureRmVM -ResourceGroupName "xx-RG-xx-DEv" -Name "xx-xx-vm-DEV"
$storageAccountName = $output.StorageProfile.OsDisk.Vhd.Uri.Split("/")[2].Split(".")[0]
Get-AzureRmStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName "xx-RG-xx-DEv"
Each of a vm's disks is going to be stored in a given blob, with the blob's uri containing the storage account name. 每个vm的磁盘都将存储在给定的blob中,blob的uri包含存储帐户名。 For example:
例如:
https://mystorageaccount.blob.core.windows.net/vhds/myosdisk.vhd
You'd need to retrieve the various os disk and data disk uri's from your vm's and then parse the uri accordingly. 您需要从vm中检索各种os磁盘和数据磁盘uri,然后相应地解析uri。 Here's a way to get the storage account for each disk by first grabbing the base uri (
mystorageaccount.blob.core.windows.net
) and then taking the first string segment (separated by dot characters). 这是通过首先获取基础uri(
mystorageaccount.blob.core.windows.net
)然后获取第一个字符串段(由点字符分隔)来获取每个磁盘的存储帐户的方法。
For the OS disk: 对于操作系统磁盘:
Get-AzureVM -ServiceName myservice -Name myvmname |
GetAzureOSDisk |
ForEach-Object { $_.MediaLink.Host.split(".")[0] }
And likewise for data disks: 同样对于数据磁盘:
Get-AzureVM -ServiceName myservice -Name myvmname |
GetAzureDataDisk |
ForEach-Object { $_.MediaLink.Host.split(".")[0] }
You'll get duplicate storage account names if you used the same storage account for more than one disk. 如果您对多个磁盘使用相同的存储帐户,则会获得重复的存储帐户名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.