0
votes

I`m following the documentation: https://googlecloudplatform.github.io/google-cloud-powershell/#/google-compute-engine/GceInstance/Set-GceInstance

I cant get the following code working:

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

When I replace $disk for disk-snapshot-instance-1 I get the same error:

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

The thing I don't understand is that it works for me to remove a disk when attaching it manually through the G-cloud interface.

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

My question: Why can't I attach a disk to an instance with the above code, while removing the disk works?

1
Did you resolve this? If not, I'll try to repro it for you this afternoon. Are you using Get-GceDisk to set $disk before the remove too? - DazWilkin

1 Answers

0
votes

The correct commands are:

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

I create an instance with 2 disks using gcloud and then:

Get-GceDisk | Format-List -Property Name

This returns:

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

Then I can:

$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