?
Solved

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

Posted on 2014-02-20
3
Medium Priority
?
702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Abhilash earned 1500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Teach the user how to edit .vmx files to add advanced configuration options Open vSphere Web Client: Edit Settings for a VM: Choose VM Options -> Advanced: Add Configuration Parameters:
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

752 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