Azure虚拟机非托管磁盘大小调整

想要扩容一个Azure VM 的磁盘空间,门户里面竟然无法扩展,点点鼠标就完事的时代在离去,微软越来不想微软。

在门户里面即便使用Azure Cli命令行也不行。

PS /home/gpchina> az disk list

返回为空,根本没有返回磁盘。

不过使用 vm unmanaged-disk list可以看到磁盘。

PS /home/gpchina>az vm unmanaged-disk list

但是 az vm unmanaged-disk只有分离和附加的命令,无法扩容磁盘空间命令。

az vm unmanaged-disk attach

az vm unmanaged-disk detach

az vm unmanaged-disk list

List unmanaged disks of a VM.

看着微软的KB,掉头去Powershell里面处理。
--.查看power shell版本

$PSVersionTable.PSVersion

PS Z:\> $PSVersionTable.PSVersion

Major Minor Build Revision


5 1 17763 6414

--查看是否已经安装Azure

PS Z:\> Get-Module -Name AzureRM -ListAvailable

--更新安装

PS Z:\> Install-Module -Name PowerShellGet -Force

PS Z:\> Install-Module -Name Az -Repository PSGallery -Force

--设置当前会话的执行策略

PS Z:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Execution Policy Change

The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose

you to the security risks described in the about_Execution_Policies help topic at

https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?

Y Yes A Yes to All N No L No to All S Suspend ? Help (default is "N"): y

--获取当前会话的执行策略的结果

PS Z:\> Get-ExecutionPolicy -List

Scope ExecutionPolicy


MachinePolicy Undefined

UserPolicy Undefined

Process Undefined

CurrentUser RemoteSigned

LocalMachine RemoteSigned

--连接Azure,输入用户名密码登录

PS Z:\> Connect-AzAccount

Please select the account you want to login with.

Retrieving subscriptions for the selection...

Announcements

With the new Azure PowerShell login experience, you can select the subscription you want to use more easily. Learn more about it and its configuration at https://go.microsoft.com/fwlink.

If you encounter any problem, please open an issue at: https://aka.ms/azpsissue

Subscription name Tenant


Pay-As-You-Go company china, Inc.
--连接服务器

PS Z:\>$rgName = 'MyRESOURCE'

PS Z:\> $vmName = 'FILESERVER'

PS Z:\>vm = Get-AzVM -ResourceGroupName rgName -Name $vmName

PS Z:\> ($vm.StorageProfile).DataDisks

Name : Fileserver-20230501-103834

DiskSizeGB : 1500

Lun : 0

Caching : None

CreateOption : Attach

SourceImage :

SourceResource :

DetachOption :

ToBeDetached : False

VirtualHardDisk :

Name : Fileserver-20230501-145230

DiskSizeGB : 1300

Lun : 1

Caching : None

CreateOption : Attach

SourceImage :

SourceResource :

DetachOption :

ToBeDetached : False

VirtualHardDisk :

--关机

PS Z:\> Stop-AzVM -ResourceGroupName rgName -Name vmName

Virtual machine stopping operation

This cmdlet will stop the specified virtual machine. Do you want to continue?

Y Yes N No S Suspend ? Help (default is "Y"): y

OperationId : c89526d4-88a7-439f-9905-a1cd6e6a8da0

Status : Succeeded

StartTime : 12/6/2024 12:22:26 PM

EndTime : 12/6/2024 12:23:47 PM

Error :

--扩容

PS Z:\>$vm.StorageProfile.DataDisks0.DiskSizeGB = 1800
--更新

PS Z:\> Update-AzVM -ResourceGroupName rgName -VM vm

RequestId IsSuccessStatusCode StatusCode ReasonPhrase


True OK

--开机

PS Z:\> Start-AzVM -ResourceGroupName rgName -Name vmName

OperationId : fb870d09-9601-4910-bb07-5d58b7915ec0

Status : Succeeded

StartTime : 12/6/2024 12:27:07 PM

EndTime : 12/6/2024 12:27:29 PM

Error :

--登录window系统中扩分区。

相关推荐
步步为营DotNet14 小时前
借助 Microsoft.Extensions.AI 与 ASP.NET Core 10 实现智能 Web 应用故障预测
人工智能·microsoft·asp.net
YHHLAI20 小时前
Agent 智能体开发实战 · 第四课:完整工具集 —— 打造 AI 编程 Agent 的工具箱
人工智能·windows·microsoft
Tom·Ge1 天前
【Spring Boot 4】Spring Boot 4.0 AI Agent实战:Skills Agent + MCP协议集成
人工智能·spring boot·microsoft
time展天11 天前
.NET 10 使用 Microsoft.AspNetCore.OpenApi 实现 API 版本管理
microsoft·.net
GlobalInfo1 天前
行业报告解读:可穿戴电子织物市场扩张背后,有哪些新机遇?
人工智能·物联网·microsoft
IT大白鼠1 天前
CVE-2026-7531 Azure Linux MariaDB PQC 内存破坏漏洞详解
linux·mariadb·azure·cve-2026-7531
weixin_BYSJ19872 天前
SpringBoot + MySQL 乒乓球运动员信息管理系统项目实战--附源码04954
java·javascript·spring boot·python·django·flask·php
公子小六2 天前
基于.NET的Windows窗体编程之WinForms图像控件
windows·microsoft·c#·.net·winforms
纸小铭2 天前
[MAF预定义ChatClient中间件-01]LoggingChatClient——在调用LLM前后输出日志
python·中间件·flask
一只小bit2 天前
LangChain 核型组件与消息管理及提示词模版
windows·microsoft·langchain