用于创建 OSDisk 和 DataDisk 快照的 Powershell 命令

Powershell command for Create OSDisk and DataDisk snapshot

我正在编写用于捕获 OS-Azure VM 磁盘快照的 powershell 脚本,但是在配置快照时我遇到了一些错误。 我正在使用以下命令创建 snapshot.I 我正在使用托管磁盘。

New-AzSnapshotConfig -OsType Linux -CreateOption copy -SourceUri Microsoft.Azure.Management.Compute.Models.OSDisk -DiskSizeGB 40 -Location 'East US'

不知道该怎么做。如果有人能帮我解决这个问题。

输出

WARNING: Breaking changes in the cmdlet 'New-AzSnapshotConfig' :
WARNING:  - "The output type 'Microsoft.Azure.Commands.Compute.Automation.Models.PSSnapshot' is changing"
 - The following properties in the output type are being deprecated :
 'EncryptionSettings'
- The following properties are being added to the output type :
 'EncryptionSettingsCollection' 'HyperVGeneration'


WARNING: NOTE : Go to https://aka.ms/azps-changewarnings for steps to suppress this breaking change warning, and other information on breaking changes in 
Azure PowerShell.


ResourceGroupName            : 
ManagedBy                    : 
Sku                          : 
TimeCreated                  : 
OsType                       : Linux
HyperVGeneration             : 
CreationData                 : Microsoft.Azure.Management.Compute.Models.CreationData
DiskSizeGB                   : 40
EncryptionSettingsCollection : 
ProvisioningState            : 
Id                           : 
Name                         : 
Type                         : 
Location                     : East US
Tags                         : 
EncryptionSettings           : 

Thanks
Rohit

你有没有去警告提示中提供的link?它says very clearly:

How do I get rid of the warnings?

To suppress these warning messages, set the environment variable 'SuppressAzurePowerShellBreakingChangeWarnings' to 'true'.

Set-Item Env:\SuppressAzurePowerShellBreakingChangeWarnings "true"

错误消息试图告诉您,您在提供的输出中看到的 属性 EncryptionSettings 很快将从某种类型的单个 属性 更改为集合 属性,您必须迭代才能找到所有设置。他们试图让您知道,如果您将 New-AzSnapshotConfig 的输出捕获到一个变量然后调用 $variable.EncryptionSettings,您的代码现在可以工作,但在下一个重大变更版本中,该调用将停止工作。最有可能的是,由于 属性 将不再存在,该调用的结果将只是 $NULL.

因此,禁止显示此警告需要您自担风险,因为 Microsoft 正尝试在此处为您提供服务,并让您知道如果您不对此采取措施,您的代码可能会中断。但是,如果您确定自己从未引用过 属性,那么您就没有什么可担心的。