What is the operating system of the vm which harddisk you try to extend? Because the only supported operating systems in PowerCLI 5.1 Release 2 for extending a hard disk with the Set-HardDisk cmdlet are:
Windows XP 32 SP3, Windows Server 2003 32bit SP2, Windows Server 2003 64bit SP2, Windows 7 64 bit, Windows Server 2008 R2 64bit, and Redhat Enterprise 5 guest operating systems.
To extend a operating system disk you need a helper vm. All virtual machines associated with the disk and the helper virtual machine should be powered off before expanding the disk.
The command becomes:
Get-VM-Nametestvm |Get-HardDisk |Where-Object {$_.Name -eq"Hard disk 1"} |Set-HardDisk-CapacityKB39845888-HelperVM (Get-VM-NameHelperVM) -HostCredential$hostCred-GuestCredential$guestCred