Skip to main content

How to extend multiple Windows VM's HDD in VMware vCenter with PowerShell PowerCLI

If you want to extend multiple VM's HDD drive in one go, below script is useful. I've extended 10 Windows VM's HDD in 4 minutes. 
Create below script in notepad and save as "extendhdd.ps1". At the same time create another text file and put all servers line by line.

eg. in host.txt

server1
server2
server3



So if you want to run the script, open your PowerCLI from one of the servers and put two files "

___extendhdd.ps1____

$GuestUser="domain\account"
$GuestPassword="xxxx"

$hosts = get-content hosts.txt

foreach ($server in $hosts) {

Get-HardDisk -vm $server | where {$_.Name -eq "Hard Disk 2"} | Set-HardDisk -CapacityKB 15728640 -Confirm:$false

Invoke-VMScript -VM $server -ScriptText "ECHO RESCAN > F:\DiskPart.txt && ECHO SELECT Volume F >> F:\DiskPart.txt && ECHO EXTEND >> F:\DiskPart.txt && ECHO EXIT >> F:\DiskPart.txt && DiskPart.exe /s F:\DiskPart.txt && DEL F:\DiskPart.txt /Q" -ScriptType BAT -GuestUser $GuestUser -GuestPassword $GuestPassword
}

__________________

You can change "Hard Disk 2" base on your requirement.


Below is output result.



PowerCLI F:\> .\extendhdd.pS1


StorageFormat   : Thick
Persistence     : Persistent
DiskType        : Flat
Filename        : [CLUW2K8] SERVER9/SERVER9_1.vmdk
CapacityKB      : 15728640
ParentId        : VirtualMachine-vm-66031
Parent          : SERVER9
Uid             : /VIServer=@mylabvcenter1:443/VirtualMachine=VirtualMachine-vm-66031/HardDisk=2001/
ConnectionState :
ExtensionData   : VMware.Vim.VirtualDisk
Id              : VirtualMachine-vm-66031/2001
Name            : Hard disk 2

WARNING: The version of VMware Tools on VM 'SERVER9' is out of date and may cause Invoke-VMScript to work improperly.
ScriptOutput
-------------------------------------------------------------------------------------------------------------------------------------------
|  Microsoft DiskPart version 6.3.9600
|
|  Copyright (C) 1999-2013 Microsoft Corporation.
|  On computer: SERVER9
|
|  Please wait while DiskPart scans your configuration...
|
|  DiskPart has finished scanning your configuration.
|
|  Volume 2 is the selected volume.
|
|  DiskPart successfully extended the volume.
|
|  Leaving DiskPart...
|
-------------------------------------------------------------------------------------------------------------------------------------------

Comments

Popular posts from this blog

Unable to launch IPMI with Java version 1.8.131

I have issue with launching IPMI after java JRE version update 1.8.131. "Error: unsigned application requesting unrestricted access to system the following resource is signed with a weak signature algorithm MD5withRSA and is treated as unsigned" The resolution is you can comment out java.security under C:\Program Files\Java\jre1.8.0_131\lib\security #jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024 you will able to launch JNLP file without issue.

How to fix Kubernetes Cluster Error IP:6443 , localhost:8080 was refused

First issue was IP:6443 was refused. Recently I build kubernetes 3 nodes clusters and forget to change IP as static. After a few days the master node IP was changed and I received the following error while running kubectl command. myo@master-node:~$ kubectl get nodes The connection to the server 192.168.1.132:6443 was refused - did you specify the right host or port? I found the following command solved the issue. sudo -i swapoff -a exit strace -eopenat kubectl version Here is the result. myo@master-node:~$ sudo -i root@master-node:~# swapoff -a root@master-node:~# exit logout myo@master-node:~$ strace -eopenat kubectl version openat(AT_FDCWD, "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size", O_RDONLY) = 3 openat(AT_FDCWD, "/etc/passwd", O_RDONLY|O_CLOEXEC) = 3 Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.5", GitCommit:"e6503f8d8f769ace2f338794c914a96fc335df0f", GitTreeState:"clean", Bui...