Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 217289

Re: PowerCLI - Get SDRS datastore recommendation to deploy VM via Scorch

$
0
0

Seems it also needs the PodDiskLocator.

Try like this

 

$clusterName='ClusterName'

$dscName='DatastoreCluster'

$hdSizeGB=100

$dsc=Get-DatastoreCluster-Name $dscName

$cluster=Get-Cluster-Name $clusterName

$rp=Get-ResourcePool-Name Resources -Location $cluster

$esx=Get-VMHost-Location $cluster|Get-Random

$dc=Get-Datacenter-Cluster $cluster

$folder=Get-Folder-Name vm -Location $dc

$pod=New-Object VMware.Vim.StorageDrsPodSelectionSpec

$pod.storagePod=$dsc.ExtensionData.MoRef

$storMgr=Get-View StorageResourceManager

$spec=New-Object VMware.Vim.StoragePlacementSpec

$spec.type=[VMware.Vim.StoragePlacementSpecPlacementType]::create


$pod=New-Object VMware.Vim.StorageDrsPodSelectionSpec

$pod.storagePod=$dsc.ExtensionData.MoRef

$initialVmConfig=New-Object VMware.Vim.VmPodConfigForPlacement

$initialVmConfig.StoragePod=$dsc.ExtensionData.MoRef

$pDisk=New-Object VMware.Vim.PodDiskLocator

$pDisk.DiskBackingInfo=New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$pDisk.DiskBackingInfo.FileName=''

$pDisk.DiskBackingInfo.EagerlyScrub=$false

$pDisk.DiskBackingInfo.ThinProvisioned=$false

$pDisk.DiskBackingInfo.DiskMode='persistent'

$initialVmConfig.Disk+=$pDisk

$pod.InitialVmConfig+=$initialVmConfig

$spec.PodSelectionSpec=$pod


$configSpec=New-Object VMware.Vim.VirtualMachineConfigSpec

$disk=New-Object VMware.Vim.VirtualDisk

$disk.CapacityInKB=$hdSizeGB*1MB

$backing=New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo

$backing.ThinProvisioned=$false

$backing.DiskMode='persistent'

$backing.EagerlyScrub=$false

$backing.FileName=''

$disk.Backing=$backing

$vDisk=New-Object VMware.Vim.VirtualDeviceConfigSpec

$vDisk.Device=$disk

$vDisk.Operation=[VMware.Vim.VirtualDeviceConfigSpecOperation]::add

$vDisk.FileOperation=[VMware.Vim.VirtualDeviceConfigSpecFileOperation]::create

$configSpec.DeviceChange+=$vDisk


$spec.ConfigSpec=$configSpec

$spec.ResourcePool=$rp.ExtensionData.MoRef

$spec.Host=$esx.ExtensionData.MoRef

$spec.Folder=$folder.ExtensionData.MoRef


$result=$storMgr.RecommendDatastores($spec)

if(!$result.DrsFault){

   foreach($recin$result.Recommendations){

   $rec.Action|

  Select @{N='Datastore';E={Get-View-Id $_.Destination-Property Name | Select -ExpandProperty Name}},

  Type,

   @{N='Rating';E={$rec.Rating}},

   @{N='Reason';E={$rec.Reason}}

   }

}

else{

   $result.DrsFault.FaultsByVm.Fault.LocalizedMessage

}


Viewing all articles
Browse latest Browse all 217289

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>