Hi!
I want to filter my DRS rules using some specific parameters, the problem that i have is that when using the cmdlet "where-object' it doesn't filter anything.
All my DRS rules in cluster are composed like this:
exposition_cpd_VM_category_ = internet_london_VM_gold
$clusters= "Get-Cluster"
foreach($cluster in $clusters)
{
$log= Get-Cluster $cluster |Get-DrsRule |Where-Object {$_.Name -like *$exposition_$cpd_VM_$category_} | Select Name,Enabled,Type
Write-Host $log
}
Anyone can help me?
Best regards
Ok, think I got it.
Your issue is with variable substitution in a string.
Try like this, I used a RegEx expression with an exact match
$cpd = 'london'
$category= 'silver'
foreach($cluster in Get-Cluster){
Get-DrsRule -Cluster $cluster | Where-Object {$_.Name -match "^${exposition}_${cpd}_VM_${category}$"} |
Select Name,Enabled,Type
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It would help if you showed the name of at least one of those rules.
From you line "exposition_cpd_VM_category_ = internet_london_VM_gold" I can't really determine how a DRS rule is named.
Neither from the operand in the Where-clause I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD!
I will try to explain better
All the rules are composed as follows " exposition_cpd_VM_category" , then, the rules are called like this
- internet_london_VM_gold
- internet_london_VM_silver
- internet_london_VM_bronze
- intranet_london_VM_gold
- intranet_london_VM_silver
- intranet_london_VM_bronze
Then for example ,i want to filter the rules that are
$exposition= internet
$cpd=london
$category= silver
$clusters= "Get-Cluster"
foreach($cluster in $clusters)
{
$log= Get-Cluster $cluster |Get-DrsRule |Where-Object {$_.Name -like *$exposition_$cpd_VM_$category_} | Select Name,Enabled,Type
Write-Host $log
}
If this script would working, the result would be this rule
"internet_london_VM_silver"
I hope it is understood now
Ok, think I got it.
Your issue is with variable substitution in a string.
Try like this, I used a RegEx expression with an exact match
$cpd = 'london'
$category= 'silver'
foreach($cluster in Get-Cluster){
Get-DrsRule -Cluster $cluster | Where-Object {$_.Name -match "^${exposition}_${cpd}_VM_${category}$"} |
Select Name,Enabled,Type
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks LucD is working , great job!