你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Set-AzureOSDisk

修改 Azure 虚拟机的主机缓存模式。

注意

本文档中引用的 cmdlet 用于管理使用 Azure Service Manager (ASM) API 的旧 Azure 资源。 创建新的资源时,不建议使用此旧版 PowerShell 模块,因为 ASM 计划停用。 有关详细信息,请参阅 Azure Service Manager 停用

Az PowerShell 模块是推荐的 PowerShell 模块,用于使用 PowerShell 管理 Azure 资源管理器 (ARM) 资源。

语法

Set-AzureOSDisk
   [-HostCaching] <String>
   -VM <IPersistentVM>
   [-Profile <AzureSMProfile>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]
Set-AzureOSDisk
   [[-HostCaching] <String>]
   [-ResizedSizeInGB] <Int32>
   -VM <IPersistentVM>
   [-Profile <AzureSMProfile>]
   [-InformationAction <ActionPreference>]
   [-InformationVariable <String>]
   [<CommonParameters>]

说明

Set-AzureOSDisk cmdlet 修改 Azure 虚拟机操作系统磁盘的主机缓存模式。 支持的主机缓存模式为 ReadOnly 和 ReadWrite。 如果在正在运行的虚拟机上运行此 cmdlet,该虚拟机将重启。

示例

示例 1:使用管道将主机缓存模式设置为 ReadOnly

PS C:\> Get-AzureVM -ServiceName "ContosoService" -Name "VirtualMachine02" | Set-AzureOSDisk -HostCaching "ReadOnly"

此命令使用 Get-AzureVM cmdlet 获取名为 ContosoService 的服务中名为 VirtualMachine02 的虚拟机。 该命令使用管道运算符将虚拟机传递到当前 cmdlet。 当前 cmdlet 将该虚拟机的操作系统磁盘的主机缓存模式设置为 ReadOnly。

示例 2:将主机缓存模式设置为 ReadWrite

PS C:\> $VM = Get-AzureVM -ServiceName "ContosoService" -Name "VirtualMachine02"
PS C:\> Set-AzureOSDisk "ReadWrite" -VM $myVM2

第一个命令在名为 ContosoService 的服务中获取名为 VirtualMachine02 的虚拟机,然后将其存储在变量中。

第二个命令将该虚拟机的操作系统磁盘的主机缓存模式设置为 ReadWrite。

参数

-HostCaching

指定操作系统磁盘的主机缓存属性。 有效值为:

  • ReadOnly
  • ReadWrite
类型:String
Position:0
默认值:None
必需:True
接受管道输入:False
接受通配符:False

-InformationAction

指定此 cmdlet 如何响应信息事件。

此参数的可接受值为:

  • 继续
  • 忽略
  • 询问
  • SilentlyContinue
  • 停止
  • Suspend
类型:ActionPreference
别名:infa
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-InformationVariable

指定信息变量。

类型:String
别名:iv
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Profile

指定此 cmdlet 从中读取的 Azure 配置文件。 如果未指定配置文件,此 cmdlet 将从本地默认配置文件中读取。

类型:AzureSMProfile
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-ResizedSizeInGB

指定操作系统磁盘的新大小(以 GB 为单位)。 大小必须大于当前大小。

类型:Int32
Position:1
默认值:None
必需:True
接受管道输入:False
接受通配符:False

-VM

指定此 cmdlet 修改操作系统磁盘的虚拟机。 若要获取虚拟机对象,请使用 Get-AzureVM cmdlet。

类型:IPersistentVM
别名:InputObject
Position:Named
默认值:None
必需:True
接受管道输入:True
接受通配符:False