Powershell G-cloud 附加磁盘到实例

Powershell G-cloud attach disk to instance

我正在关注文档: https://googlecloudplatform.github.io/google-cloud-powershell/#/google-compute-engine/GceInstance/Set-GceInstance

我无法使以下代码正常工作:

$disk = Get-GceDisk disk-snapshot-instance-1
Set-GceInstance -Name instance-1 -AttachDisk $disk

当我用 disk-snapshot-instance-1 替换 $disk 时,我得到同样的错误:

Set-GceInstance : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Set-GceInstance -Name instance-1 -AttachDisk $disk
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-GceInstance], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,Google.PowerShell.ComputeEngine.SetGceInstanceCmdlet

我不明白的是,当我通过G-cloud接口手动附加磁盘时,删除磁盘对我有用。

Set-GceInstance -Name instance-1 -RemoveDisk $disk

我的问题: 为什么我不能使用上述代码将磁盘附加到实例,而删除磁盘却有效?

正确的命令是:

Set-GceInstance $instance -AddDisk $disk1 -Zone $zone
Set-GceInstance $instance -RemoveDisk $disk1 -Zone $zone

我使用 gcloud 创建了一个包含 2 个磁盘的实例,然后:

Get-GceDisk | Format-List -Property Name

这个returns:

Name : disk-1
Name : disk-2
Name : instance-1

那我可以:

$zone = "us-west1-c"
$disk2 = Get-GceDisk disk-2
Set-GceInstance instance-1 -RemoveDisk $disk2 -Zone $zone
Set-GceInstance instance-1 -AddDisk $disk2 -Zone $zone

HTH