VMware Cloud Community

How to create a partition for the hard drive of a new VM?

I wrote a small PowerShell script that automates the process of creating a new VM. The script does what it should except that the new hard drive doesn't contain a partition and therefore the OS (I provide a CD drive with an ISO file) cannot install.

I couldn't find any option with New-VM and anything inside the PowerCLI documentation so I am really wondering how this can be accomplished.

I am using VMWare Workstation and not vSphere but this shouldn't make any difference from the perspective of PowerCLI and New-VM.

Kind regards,


Here is my script (the comments and the messages are in German). The important part is New-VM down below:

Anlegen einer VM mit einer ISO-Datei
Bei den DataStore-Pfaden kommt es auf die Groß-/Kleinschreibung an

# Snapin laden
Add-PsSnapin -Name VMware.VimAutomation.Core

# Konfiguration setzen - keine Zertifikatwarnung
Set-PowerCLIConfiguration -DefaultVIServerMode Single -InvalidCertificateAction Ignore -DisplayDeprecationWarnings:$True -Confirm:$False | Out-Null

# Eckdaten für die Anmeldung am VIServer festlegen
$IP = ""
$Port = "453"
$UserName = "Administrator"
$Pw = ConvertTo-SecureString -String "!secret" -AsPlainText -Force
$Cred = New-Object -Typename System.Management.Automation.PsCredential -ArgumentList $UserName, $Pw

# Verbinding zum VIServer herstellen
$VIServer = Connect-VIServer -Server $IP -Credential $Cred -Port 453 -Protocol https -ErrorAction SilentlyContinue

# Gab es ein Problem?
if (!$?)
  Write-Warning "Keine Verbindung mit VI-Server möglich."

Write-Verbose "Verbindung mit VI-Server hergestellt." -Verbose

# ISO-Ordner anlegen wenn er noch nicht existiert
$ISODataStorePath = "vmstores:\$IP@$Port\ha-datacenter\standard\ISO"
if (!(Test-Path -Path $ISODataStorePath))
   md -Path $ISODataStorePath -Verbose | Out-Null

# ISO-Datei in DataStore kopieren
$XPISOName = "de_windows_xp_professional_with_service_pack_3_x86_cd_x14-80444.iso"
if (!(Test-Path -Path $XPISOPath))
    Write-Verbose "Kopiere $XPISOName nach $ISODataStorePath" -Verbose
    Copy-DatastoreItem -Item $XPISOPath -Destination $ISODataStorePath

# VM anlegen
$VMNeu = New-VM -Name XPA -MemoryMB 768 -NetworkName "NAT" -CD -DiskGB 20 -DiskStorageFormat Thin -GuestID winXPProGuest

# CD-Laufwerk mit ISO-Path verbinden
$VMNeu | Get-CDDrive | Set-CDDrive -IsoPath "[standard] ISO\$XPISOName" -StartConnected:$True -Confirm:$False | Out-Null

# Zum Schluss die VM starten - zur Abwechslung einmal asynchron
# $VMNeu | Start-VM -Confirm:$false -RunAsync

0 Kudos
3 Replies

You should have a look at the vmkfstools.


Viele Grüße Smiley Wink


Forget what I said to --createfs. Thats on datastore level. Anyway vmkfstools should offer something that helps.


I'm afraid that PowerCLI doesn't contain any cmdlets to create partitions.

But PowerShell does contain some cmdlets to create partitions, see for example A Woops–Creating Partition and Format disk using PowerShell does not update the $ share, a post from the Deployment Bunny.

But you will need to have an environment that has PowerShell and that can access the vDisk.

Should be easy, set up a VM and install an OS on there with PowerShell.

Then attach the new vDisk to this VM and do the partitioning and formatting.

Would that be a possible solution ?

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



Thanks a lot. That clarifies what I was suspecting. I was just uncertain because VM Workstation does the partitioning for a new drive inside the UI so I had hoped there might be a "hidden feature" of New-VM that does the same thing.



0 Kudos