Closed m4c3 closed 7 years ago
Greets, @m4c3-
Right, get a DrsVMGroup by the related VM -- sounds like a great use case. I'd think that we would add something like -VM
or -RelatedObject
to Get-DrsVMGroup
so as to enable such things. Then we could do:
C:\> Get-VM myVM0 | Get-DrsVMGroup
Name Cluster UserCreated VM
---- ------- ----------- --
testVMGrp0 myClu0 True {myVM0, dtest4}
How would that be?
Hello really interesting question. I would like to retrieve all the VMs in a cluster not belonging to a DRS group. It's very common new VMs where created but an administrator could mistake the inclusion on a DRS group.
Any idea to create this code?
Hey, @m4c3
I made a commit to the feat_RelatedObj
branch (commit 0dade0a) that adds the ability to get the DrsVMGroup by the subject VM. Should work like:
C:\> Get-VM myVM0 | Get-DrsVMGroup
Name Cluster UserCreated VM
---- ------- ----------- --
testVMGrp0 myClu0 True {myVM0, dtest4}
How does that do for you? And, I intend to add similar behavior to the other Get-Drs*
cmdlets, starting with the Get-DrsVMHostGroup
cmdlet.
@mtboren I was working on a very quick script with the customer just to retrieve something similar what I was asking for. It's obvious that could be many different ways to perform this task, and if could be added to the code, some kind of function or maybe on your last post something like: Returning false if any given VM is not included on any DRSRule. Could be possible?
Code generated for customer:
$vmrule = Get-DrsVMGroup -Cluster “
foreach($vm in Get-VM){ $VMname = $vm.Name.ToString()
if ($vmrule -like "*$VMname*")
{#Write-Host -ForegroundColor Green "Estoy"
}
Else{Write-Host -ForegroundColor red "La VM $VMname no está en ninguna DRS rule "}
}
Hello, @cerosunos
Yes, interesting question indeed. We should be able to meet your need with the v1.0.3 version of the module. In order to get all of the VMs in cluster that are not in a DrsVMGroup, we could do something like:
$arrDrsVMGroups = Get-Cluster myCluster | Get-DrsVMGroup -ReturnRawGroup
## get the VMs in "myCluster" that are not in any DrsVMGroup
Get-Cluster myCluster | Get-VM | Where-Object {$arrDrsVMGroups.Vm -notcontains $_.Id}
This has a couple of advantages over some potential other ways:
-ReturnRawGroup
parameterHow does that suit your need? Cheers
@mtboren your script really works, thanks.
Alright -- released v1.1.0 in (commit https://github.com/PowerCLIGoodies/DRSRule/commit/c8c8e2899bb9dcb4da7a8a6d95070aa0cbd457e0), in which this feature (and some other related, expanded capabilities) are included. Thanks for the suggestion, @m4c3 !
Hi, is there a way to check if a VM is already in a DrsVMGroup? Or can i load all the VM Names from the Group and match them by myself?
Thanks Matthias