Reply to Message

View discussion in a popup

Replying to:
ggovek
Enthusiast
Enthusiast

Thanks for the advice. It works for Local Managers, code is Bellow:

 

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false | Out-Null
Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction:Ignore -Confirm:$false | Out-Null
# Connect to vCenter Server
Connect-VIServer -Server nsxt-vc-sdc.glab.local -User administrator@vsphere.local -Password C!sco123

# Connect to NSX-T Manager
$NSX_IP = "10.10.10.10"
$NSX_User = "admin"
$NSX_Password = "Password"

Write-Host "Connecting to NSX Manager ..."
$n = Connect-NsxServer -Server $NSX_IP -User $NSX_User -Password $NSX_Password

#Variables
$MemberType="VirtualMachine"
$Key="name"
$Operator="EQUALS"

#$GroupName="APP-02_8080"
#$Value="APP-02_8080"


$vm_names = Get-VM -Tag "NSX"
foreach ($vm_name in $vm_names) {
    $GroupName = Get-VM -Name $vm_name
    $allGroups = Invoke-ListGroupForDomain -DomainId default
    $gp = $allGroups.Results | where {$_.DisplayName -eq $GroupName}
    if ($gp) {
        Write-Host "Group $GroupName already exists."
    }else{
        $cond = Initialize-Condition -ResourceType Condition -Id $GroupName -MemberType $MemberType -Value $GroupName -Key $Key -Operator $Operator
        $group = Initialize-Group -DisplayName $GroupName -Expression @($cond)
        $createdGroup = Invoke-PatchGroupForDomain -Server $n -DomainId default -Group $group -GroupId $GroupName
        Write-Host "Created Group $GroupName ..."
    }
}

# Disconnect to NSX-T Manager
Write-Host "Disconnecting from NSX Manager ..."
Disconnect-NsxServer -Server $NSX_IP

 Could someone help me with how I could create Security Groups on the Global Manager?

Reply
0 Kudos