Solved

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

Posted on 2014-02-20
3
644 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

If we need to check who deleted a Virtual Machine from our vCenter. Looking this task in logs can be painful and spend lot of time, so the best way to check this is in the vCenter DB. Just connect to vCenter DB(default DB should be VCDB and using…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Teach the user how to configure vSphere clusters to support the VMware FT feature Open vSphere Web Client: Verify vSphere HA is enabled: Verify netowrking for vMotion and FT Logging is in place or create it: Turn On FT for a virtual machine: Verify …
This video shows you how to use a vSphere client to connect to your ESX host as the root user. Demonstrates the basic connection of bypassing certification set up. Demonstrates how to access the traditional view to begin managing your virtual mac…

863 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

24 Experts available now in Live!

Get 1:1 Help Now