Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-02-20
3
Medium Priority
?
723 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

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

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.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Teach the user how to use configure the vCenter Server storage filters Open vSphere Web Client:  Navigate to vCenter Server Advanced Settings: Add the four vCenter Server storage filters: Review the advanced settings: Modify the values of the four v…
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…

609 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