gpt4 book ai didi

powershell - 使用 PowerShell ARM 脚本将磁盘添加到 Azure VM

转载 作者:行者123 更新时间:2023-12-02 23:57:21 26 4
gpt4 key购买 nike

我尝试使用以下 PowerShell 脚本将磁盘添加到 Azure 中的 VM:

$rgName = "${resourceManager}"
$stName = "${storageAccount}"
$diskname="${diskName}"
$lun = ${lunNum}
$vmName = "${vmName}"
$diskSize=${diskSize}

$storageAcc=Get-AzureRmStorageAccount -ResourceGroupName $rgName -Name $stName
$diskpath=$storageAcc.PrimaryEndpoints.Blob.ToString() + "vhds/" + $diskname + ".vhd"
$vm = Get-AzureRmVM -ResourceGroupName $rgName -Name $vmName | Add-AzureRmVMDataDisk -Name $diskname -VhdUri $diskpath -CreateOption empty -DiskSizeInGB $diskSize -Lun $lun
$vm.Tags = $null
$vm | Update-AzureRmVM

以下是我需要的值的描述:

SubscriptionID - Azure Subscription ID
AzureUsername - Name of Azure service account. It must be configured as co-administrator on the Azure Subscription
AzurePassword - Associated Azure service account password
resourceManager - Name of Resource Manager (RM) containing the VM
storageAccount - Name of storage account (within the specified RM), where to create the new disk
diskName - desired name of the disk
diskSize - desired size of the disk in Giga Bytes, this is a quota, up to 1000 GB is allowed
lunNum - the lun number to use, valid values are 0,1,2,3, etc.
vmName - the name of an existing VM where to attach the new disk

以下是我在脚本中使用的测试值:

SubscriptionID - 06e2bb3d-e66d-4a21-a4a0-78b2fe53f8c6
AzureUsername – <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4c38293f380c23393820232327622f2321" rel="noreferrer noopener nofollow">[email protected]</a>
AzurePassword – test123
resourceManager –
storageAccount -
diskName - test
diskSize - 100
lunNum -
vmName - ALPHABETTVM001

我不确定从哪里获取 resourceManager、storageAccount 和 lunNum 输入。我正在对已从旧的 ASM 模型转换为新的 ARM 模型的 Azure 脚本进行功能测试,但我对此没有太多经验。在哪里可以找到给定虚拟机的这三个值?

最佳答案

在Azure资源模块(ARM,新)中,我们可以使用Login-AzureRmAccount通过PowerShell登录Azure。

I'm unsure where to procure the resourceManager, storageAccount, and lunNum inputs.

您可以通过PowerShell登录Azure,并列出所有资源组名称:
$rgName = "资源组名称"

Get-AzureRmResourceGroup | select resourcegroupname
ResourceGroupName
-----------------
Api-Default-North-Central-US
AppResource
CS-WebJobs-NorthCentralUS-scheduler
Default-ApplicationInsights-CentralUS
Default-Networking
Default-ServiceBus-CentralUS
Default-SQL-CentralUS
Default-Storage-EastUS
Default-Web-NorthCentralUS
DemoVS8172016
DennisSPMonitor
lb1
win

您还可以使用新门户来查找资源组: enter image description here
关于存储帐户,我们可以使用PowerShell列出资源组中的所有存储帐户(您也可以通过新门户找到存储帐户名称):

Get-AzureRmStorageAccount -ResourceGroupName win  | select storageaccountname
StorageAccountName
------------------
windiag865 (used for log)
windisks548 (used for data)

关于lunnum,如果您的虚拟机只有一个操作系统磁盘而没有数据磁盘,则第一个lunnum默认为0,当您向虚拟机添加数据磁盘后,您可以使用PowerShell列出Lun数量:

get-azurermvm -ResourceGroupName "win" -Name "win"
StorageProfile :
ImageReference :
Publisher : MicrosoftWindowsServer
Offer : WindowsServer
Sku : 2012-R2-Datacenter
Version : latest
OsDisk :
OsType : Windows
Name : win
Vhd :
Uri : https://windisks548.blob.core.windows.net/vhds/win20170111102348.vhd
Caching : ReadWrite
CreateOption : FromImage
DataDisks[0] :
Lun : 0
Name : win-20170111-103800
Vhd :
Uri : https://windisks548.blob.core.windows.net/vhds/win-20170111-103800.vhd
Caching : None
CreateOption : Empty
DiskSizeGB : 50
DataDiskNames[0] : win-20170111-103800

PS > (get-azurermvm -ResourceGroupName "win" -Name "win").StorageProfile.DataDisks.lun
0

关于powershell - 使用 PowerShell ARM 脚本将磁盘添加到 Azure VM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41566772/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com