Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 176561

PowerCLI Menu passing a variable question

$
0
0

Hello,

 

I am building a menu driven function to build dynamic criteria inside a NSX Security Group.  My issue is, the menu is populated with NSX Security Tags with the name that starts with APP-. This works great. I make a selection and I want that select to be used in dynamic criteria within a NSX Security group that gets created higher in the script which also works.

 

The Menu works like this:

 

1. APP-SCRIPTTEST  2. APP-ANSIBLE                        

3. APP-GITLAB      4. APP-FILE                           

5. APP-PRINT       6. APP-THYCOTIC                       

7. APP-REDFOREST   8. APP-ARCGIS                         

9. APP-TRIDION     10. APP-MADDWEBAPP

 

So If I chose 1. I want the condition to include APP-SCRIPTTEST in the criteria.

 

This is the menu part of the script

:

$script:c = Get-NsxSecurityTag | Where-Object { $_.Name -like 'APP-*' } | select name

$menu = for ($i = 0; $i -lt $script:c.Count; $i += 2)

{

$obj = [ordered]@{

Odd = "$($i+1). $($script:c[$i].Name)"

}

if ($script:c[$i + 1])

{

$obj.Add('Even', "$($i+2). $($script:c[$i+1].Name)")

}

New-Object PSObject -Property $obj

}

$menu | Format-Table -HideTableHeaders

$choice = Read-Host -Prompt "Please Select The Security Tag (1..$($script:c.Count))"

 

This is the part of the script that builds the dynamic criteria. $script:a is the Security Group which gets built earlier in the script. $script:q is a String that also gets inputed earlier in the script, this also works. The part that does work is highlighted in yellow. passing the selected NSX Security Tag into the criteria.

 

Get-NsxSecurityGroup $script:a | Add-NsxDynamicMemberSet -DynamicCriteriaSpec (New-NsxDynamicCriteriaSpec -key VMName -Condition starts_with -Value $script:q) -CriteriaOperator ALL

Get-NsxSecurityGroup $script:a | Get-NsxDynamicMemberSet -Index 1 | Add-NsxDynamicCriteria -Key SecurityTag -Condition equals -value Get-NsxSecurityTag $script:c[$choice - 1].name

  Get-NsxSecurityGroup $script:a | Get-NsxDynamicMemberSet -Index 1 | Add-NsxDynamicCriteria -Entity (Get-NsxSecurityGroup -name $x)

 

I have tried this a couple ways:

 

Get-NsxSecurityGroup $script:a | Get-NsxDynamicMemberSet -Index 1 | Add-NsxDynamicCriteria -Key SecurityTag -Condition equals -value Get-NsxSecurityTag $script:c[$choice - 1].name

 

Get-NsxSecurityGroup $script:a | Get-NsxDynamicMemberSet -Index 1 | Add-NsxDynamicCriteria -Key SecurityTag -Condition equals -value Get-NsxSecurityTag ($script:c[$choice - 1].name)

 

Get-NsxSecurityGroup $script:a | Get-NsxDynamicMemberSet -Index 1 | Add-NsxDynamicCriteria -Key SecurityTag -Condition equals -value $script:c

 

Any ideas? I am guessing I am just missing something very obvious. But this script is very large almost 800 lines and I am starting to see double. :-) As always thanks for the help.


Viewing all articles
Browse latest Browse all 176561

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>