Flapoly
Contributor
Contributor

How to create a eagerZeroedThick disk with Powershell

Jump to solution

Hi all,

I would like to create a eagerZeroedThick disk with power (This is required for shared MSCS cluster disks) with powershell...

looks like this is not available as part of the VIPowershell cmdlet

I have the following code... but it fails during the CreateVirtualDisk. Please can you help me ?

Write-Host "Retreive: Service Instance..."

$svcRef = new-object VMWare.Vim.ManagedObjectReference

$svcRef.Type = "ServiceInstance"

$svcRef.Value = "ServiceInstance"

$serviceInstance = get-view $svcRef

#

Write-Host "Retreive: Virtual Disk Manager

$vdm = Get-View $serviceInstance.Content.VirtualDiskManager

#

Write-Host "Retreive: New virtual HDD Spec"

$vHddSpec = new-Object VMWare.Vim.FileBackedVirtualDiskSpec

$vHddSpec.CapaciptyKB = 102400

$vHddSpec.DiskType = "eagerZeroedThick" # mandatory for Shared Cluster disk

$vHddSpec.AdapterType = "lsiLogic" # mandatory for Shared Cluster disk

#

Write-Host "Create cluster disk"

$FilePath ="[HQESXU0021_Local] /Test1.vmdk"

$ds = Get-datastore HQESXU0021_Local

$vdm.CreateVirtualDisk ($FilePath, $ds, $vHddSpec)

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Note1: the trick when you want to use the VirtualDiskManager methods you need to connect to the ESX server not the VC!

Note2: the name of the disk needs to be a valid datastore path.

That means you have to use the following notation: \[

Note that there has to eb a space between the closing square bracket and the name of the folder.

An example: \[myds\] vm1/vm1-quorum.vmdk

Note3: when you connect to the ESX server there is only 1 datacenter with the default name "ha-datacenter"

Note4: the CreateVirtualDisk method doesn't connect the new disk to any virtual machine.

The script then becomes something like this

Connect-VIServer -Server <ESX-servername> -User <ESX-account> -Password <ESX-password>

Write-Host "Retreive: Service Instance..."
$serviceInstance = get-view ServiceInstance
#
Write-Host "Retrieve: Virtual Disk Manager"
$vdm = Get-View $serviceInstance.Content.VirtualDiskManager
#
Write-Host "Retrieve: New virtual HDD Spec"
$vHddSpec = new-Object VMWare.Vim.FileBackedVirtualDiskSpec
$vHddSpec.CapacityKB = 102400
$vHddSpec.DiskType = "eagerZeroedThick"      # mandatory for Shared Cluster disk
$vHddSpec.AdapterType = "lsiLogic"           # mandatory for Shared Cluster disk
#
Write-Host "Create cluster disk"
$FilePath ="[myds] Cluster/cluster-quorum.vmdk"
$dc = Get-datacenter "ha-datacenter" | Get-View

$vdm.CreateVirtualDisk($FilePath, $dc.moref, $vHddSpec)


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership

Note1: the trick when you want to use the VirtualDiskManager methods you need to connect to the ESX server not the VC!

Note2: the name of the disk needs to be a valid datastore path.

That means you have to use the following notation: \[

Note that there has to eb a space between the closing square bracket and the name of the folder.

An example: \[myds\] vm1/vm1-quorum.vmdk

Note3: when you connect to the ESX server there is only 1 datacenter with the default name "ha-datacenter"

Note4: the CreateVirtualDisk method doesn't connect the new disk to any virtual machine.

The script then becomes something like this

Connect-VIServer -Server <ESX-servername> -User <ESX-account> -Password <ESX-password>

Write-Host "Retreive: Service Instance..."
$serviceInstance = get-view ServiceInstance
#
Write-Host "Retrieve: Virtual Disk Manager"
$vdm = Get-View $serviceInstance.Content.VirtualDiskManager
#
Write-Host "Retrieve: New virtual HDD Spec"
$vHddSpec = new-Object VMWare.Vim.FileBackedVirtualDiskSpec
$vHddSpec.CapacityKB = 102400
$vHddSpec.DiskType = "eagerZeroedThick"      # mandatory for Shared Cluster disk
$vHddSpec.AdapterType = "lsiLogic"           # mandatory for Shared Cluster disk
#
Write-Host "Create cluster disk"
$FilePath ="[myds] Cluster/cluster-quorum.vmdk"
$dc = Get-datacenter "ha-datacenter" | Get-View

$vdm.CreateVirtualDisk($FilePath, $dc.moref, $vHddSpec)


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

View solution in original post

0 Kudos
Flapoly
Contributor
Contributor

Hi LucD

you completly answer my question. Thks a lot

The missing part was

$dc = Get-datacenter "ha-datacenter" | Get-View

0 Kudos