Solved

VMWAre: Adding a new disk to VM with affinity rules off

Posted on 2014-02-20
3
611 Views
Last Modified: 2014-02-22
I have this script:

$ourVm = Get-VM $vmname  
$ourDisk = $ourVm | Get-HardDisk  
$antiAffinityRule = New-Object 'VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMDiskAntiAffinityRule' $ourDisk
New-HardDisk -VM $ourVm -AdvancedOption $antiAffinityRule -CapacityGB 300 -Datastore $datastorecluster

Open in new window


This is to be able to add a disk to a VM in a datastore cluster with enough space, but the VM itself is on a datastore in that cluster that does not have enough space for the disk. By turning the affinity rule settings off I am hoping to add the new disk on a datastore in the cluster where there is enough space, even if that is not together with the VM.

The script is the same as what can be found in Example 5 here:
https://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/New-HardDisk.html

I get this error:

New-HardDisk : 20.02.2014 09:55:54    New-HardDisk        A specified parameter
 was not correct.
StoragePlacementSpec.podSelectionSpec.initialVmConfig[].vmConfig.intraVmAntiAff
inity
At line:1 char:1
+ New-HardDisk -VM $ourVm -AdvancedOption $antiAffinityRule -CapacityGB 300 -Da
tas ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : NotSpecified: (:) [New-HardDisk], InvalidArgumen
   t
    + FullyQualifiedErrorId : Client20_VirtualDeviceServiceImpl_NewVirtualHard
   Disk_ReconfigError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDev
  ice.NewHardDisk
0
Comment
Question by:itnifl
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Abhilash earned 500 total points
ID: 39872834
In the last parameter which says
-Datastore $datastorecluster
You have not defined $datastorecluster anywhere in the script.
Go to your vCenter and see what is the name of the Datastore cluster. For example you might have named the cluster as Example_Cluster.
So modify the last parameter as
-Datastore Example_Cluster

See if it works.
0
 
LVL 2

Author Comment

by:itnifl
ID: 39872935
You are right in my initial example I forgot to initiate the variable datastorecluster. However, in my full script the datastorecluster variable gets initiated like this:

(get-datastorecluster -datastore (get-datastore -VMHost (Get-Cluster -VM $vmname | get-vmhost)[0])) | %{
	if($dataStoreClusters.name -notcontains $_.name) {
		$dataStoreClusters += @{"name" = $_.name; "freePercentage" = "{0:P0}" -f ($_.FreeSpaceGB / $_.CapacityGB)}
	}
}
$selectedDataStore = @{"name" = "NA"; "freePercentage" = "0 %"}

foreach($dataStoreCluster in $dataStoreClusters) {
	$excluded = $exclusionList -contains $datastoreCluster.name
	if(!$excluded) {
		$freePercentage1 = $dataStoreCluster.freePercentage
		$freePercentage2 = $selectedDataStore.freePercentage	
		if(([int]$freePercentage1.substring(0,$freePercentage1.length - 2)) -gt ([int]$freePercentage2.substring(0,$freePercentage2.length - 2))) {
			$lowpri = $lowPriorityList -contains $dataStoreCluster.name
			if((!$lowpri -and [int]$freePercentage1.substring(0,$freePercentage1.length - 2) -gt 9) -or ($lowpri -and $freePercentage2.substring(0,$freePercentage2.length - 2) -lt 10)) {
				$selectedDataStore = $dataStoreCluster
			} 
		}
	}
}
$selectedDataStoreName = $selectedDataStore.name
$datastorecluster = $selectedDataStoreName.toUpper()

Open in new window


This makes for the wrong datastorecluster, even if it is available to the hosts that host the VM. I guess I need to initiate it with the datastore cluster name where the vmx file is, how do I do that?
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 39879009
You got the answert correct, even though it wasn't all i was after . I will start a new question that is more on point.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Join & Write a Comment

This article will help you understand what HashTables are and how to use them in PowerShell.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Teach the user how to install ESXi 5.5 and configure the management network System Requirements: ESXi Installation:  Management Network Configuration: Management Network Testing:
This Micro Tutorial steps you through the configuration steps to configure your ESXi host Management Network settings and test the management network, ensure the host is recognized by the DNS Server, configure a new password, and the troubleshooting…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now