VMware Cloud Community
jacquesp0
Contributor
Contributor
Jump to solution

Set-HardDisk Error

Hi all,

I had to increase the size of some VMDKs today and did not want to do it manually. So I thought, I'd give PowerCLI a shot.

My script is supposed to set the size of all the VMDKs with a certain name in a certain datastore to roughly 50GB. All the harddisks that are being selected are 10GB in size but Set-HardDisk gives me an error saying that it can only expand/extend (forgot the exact wording) the harddisks. Apparently it thinks that my disks are larger than the target size? This is not the case and if I run the command manually for one VM the command does what it's supposed to do. I have no idea what could cause this behaviour.

Maybe someone can have a look at my script and see if there's something wrong with it?

At some point to command gave me an error saying something like that I had to connect to a host directly that's why my script might look a little weird.

I must mention that this is my first PowerShell script ever and that I

have no programming background so please don't laugh too hard

Thank you in advance!

Script:

0 Kudos
1 Solution

Accepted Solutions
ykalchev
VMware Employee
VMware Employee
Jump to solution

Hi,

As you correctly noticed Get-HardDisk -Datastore needs direct ESX connection. In this case the cmdlet uses the VirtualDiskManager to query directly information from the vmdk file. This is also the reason why Persistence property is unknown - this information is available through the VM ( Get-HardDisk -VM myVM).

However even if you get harddisk browsing the Datastore, extend operation should be suitable.

The error you get is because HostUser, HostPassword, GuestUser and GuestPassword says to cmdlet to extend the hard disk and to resize the hdd in the guest OS of the VM. If you want to do that you need to get the hdd using the VM it's attached to.

So removing this parameters should extend the vmdk file as you want to:


connect-viserver -server $vmhosts[0] -user $huname -password $hpword
$vmharddisks = Get-HardDisk -DataStore VMFS-OS-LUN100 | where { $_.filename -like "*HD*"}
foreach ($vmharddisk in $vmharddisks) {
        Set-HardDisk -HardDisk $vmharddisk -CapacityKB $cap
}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team

View solution in original post

0 Kudos
7 Replies
LucD
Leadership
Leadership
Jump to solution

Could you by any chance have snapshots on any of those VMs ?

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

jacquesp0
Contributor
Contributor
Jump to solution

I don't think so but I don't know for sure. I'll chek tomorrow. Thanks for pointing that out to me.

I think the first server that is being returned from the Get-VMHost command is the one which I have already resized to test the Set-HardDisk command line. Could that be a problem?

But in principle it's correct to connect to the host instead of the vCenter, yeah?

0 Kudos
jacquesp0
Contributor
Contributor
Jump to solution

Could you by any chance have snapshots on any of those VMs ?

____________

Blog: LucD notes

Twitter: lucd22

I've checked to see if there are snapshots but there aren't any.

This is the exact wording of the error message:

Set-HardDisk : 5/19/2010 1:55:21 PM Set-HardDisk 52516db1-24dd-01dd-19a5-6abe3b67ca38 Virtual hard disk obtained by datastore path can be only extended.

At line:3 char:17

+ Set-HardDisk <<<< -HardDisk $vmharddisk -CapacityKB $cap -HostUser $huname -HostPassword $hpword -GuestUser $guname -GuestPassword $gpword

Is it possible that Get-HardDisk with the -DataStore switch just isn't suitable for this operation for whatever reason?

I think it's suspicous to see that a Get-HardDisk HD (let's assume the name contains the string "HD") will give me information on whether the disk is persistent but a Get-HardDisk -DataStore will give me a column full of "Unknown"

Or maybe there's another way to filter disks by DataStore and a string in the filename?

0 Kudos
ykalchev
VMware Employee
VMware Employee
Jump to solution

Hi,

As you correctly noticed Get-HardDisk -Datastore needs direct ESX connection. In this case the cmdlet uses the VirtualDiskManager to query directly information from the vmdk file. This is also the reason why Persistence property is unknown - this information is available through the VM ( Get-HardDisk -VM myVM).

However even if you get harddisk browsing the Datastore, extend operation should be suitable.

The error you get is because HostUser, HostPassword, GuestUser and GuestPassword says to cmdlet to extend the hard disk and to resize the hdd in the guest OS of the VM. If you want to do that you need to get the hdd using the VM it's attached to.

So removing this parameters should extend the vmdk file as you want to:


connect-viserver -server $vmhosts[0] -user $huname -password $hpword
$vmharddisks = Get-HardDisk -DataStore VMFS-OS-LUN100 | where { $_.filename -like "*HD*"}
foreach ($vmharddisk in $vmharddisks) {
        Set-HardDisk -HardDisk $vmharddisk -CapacityKB $cap
}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yasen, that is rather important information. Thanks for that.

Perhaps this should be mentioned in the Cmdlets Reference.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
jacquesp0
Contributor
Contributor
Jump to solution

Thank you very much indeed for your answer!

That did the trick Smiley Happy

As for the -Host... and -Guest... parameters. I had no idea! Thanks for pointing that out to me/us!

0 Kudos
ykalchev
VMware Employee
VMware Employee
Jump to solution

Thanks for the note.

We should definitely put more information about this in the help since this cmdlet became rather complicated.

/Yasen

Yasen Kalchev, vSM Dev Team
0 Kudos