Some VMs have a custom attribute that specifies cluster nodes, I need to merge those nodes into one drs rule and make sure they are separated from each other.
Here is an example
$Nodes = VM1,VM2,VM3,VM4|Get-Annotation -CustomAttribute "Nodes"|?{$_.Value -ne ""}|select Value -Unique
$Nodes
Value
-----
VM1;VM3
VM2;VM4
After collecting these attributes, I do not understand what to do next, I try to separate values, but nothing comes out
foreach ($Node in $Nodes){
get-vm ($Node.value -replace ";", ",")
}
Get-VM VM with name 'VM1;VM3' was not found using the specified filter(s).
@LucDCan you help me?
Ideally, check for rules with current VMs and skip if they exist
Do you mean like this?
Get-VM | Get-Annotation -CustomAttribute Nodes |
Where-Object { $_.Value -ne '' } |
Select-Object -Property Value -Unique |
ForEach-Object -Process {
$vmNames = $_.Value.Split(';')
New-DrsRule -Cluster 'cluster' -Name "Rule-$($vmNames -join '-')" -VM $vmNames -KeepTogether:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure how these Custom Attributes are related to DRS VM Groups?
Can you elaborate?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For example, there are 2 VMs with a database
VM1 - Primary
VM2 - Secondary
For each VM in the attributes, we indicate all members of the cluster database
Based on these data, I need to make a separate drs rule
You mean something like this?
$vm = Get-VM | Get-Annotation -CustomAttribute Nodes |
Where-Object { $_.Value -ne '' } |
Select-Object -ExpandProperty AnnotatedEntity
New-DrsVMGroup -Cluster 'cluster' -Name 'Groupname' -VM $vm
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It works if all VMs are added to one rule.
But here the task is a little different.
There is a VM
VM1 value VM1; VM2
VM2 value VM1; VM2
VM3 value VM3; VM4
VM4 value VM3; VM4
So I need to make 2 different rules
for VM1; VM2 and VM3; VM4
Not following.
You need 2 VM groups, but based on what?
Do they have different values in the Custom Attribute?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I have 100 VMs for every 2 VMs (there are also clusters of 3 VMs) the same attribute, 50 rules need to be made for these 100 VMs
Still not following I'm afraid.
How can the script know which 2 (or 3) VMs need to go in 1 group, if they all have the same Custom Attribute?
Or are there multiple clusters, with each having 2 or 3 VMs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
As a first step, I selected all the unique values of the NODES attribute
$Nodes = get-vm|Get-Annotation -CustomAttribute "Nodes"|?{$_.Value -ne ""}|select Value -Unique
Next, I want to take each value in turn and split it into VMs and create a rule.
Do you mean like this?
Get-VM | Get-Annotation -CustomAttribute Nodes |
Where-Object { $_.Value -ne '' } |
Select-Object -Property Value -Unique |
ForEach-Object -Process {
$vmNames = $_.Value.Split(';')
New-DrsRule -Cluster 'cluster' -Name "Rule-$($vmNames -join '-')" -VM $vmNames -KeepTogether:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference