<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create NSX-T Security Groups with PowerCLI in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963870#M111553</link>
    <description>&lt;P&gt;Thanks for the advice. It works for Local Managers, code is Bellow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Could someone help me with how I could create Security Groups on the Global Manager?&lt;/P&gt;</description>
    <pubDate>Fri, 14 Apr 2023 14:07:54 GMT</pubDate>
    <dc:creator>ggovek</dc:creator>
    <dc:date>2023-04-14T14:07:54Z</dc:date>
    <item>
      <title>Create NSX-T Security Groups with PowerCLI</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963837#M111549</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;With Code bellow I want to create Security Groups:&lt;/P&gt;&lt;P&gt;#VM NAME&lt;BR /&gt;#Variables&lt;BR /&gt;$VMs= Get-VM -Name "APP-01_8080"&lt;BR /&gt;$nsgroupname = $VMs.Name&lt;BR /&gt;#Create NSGroup&lt;BR /&gt;$nsgroupsvc = Get-NsxtService -Name com.vmware.nsx.ns_groups&lt;BR /&gt;$nsgroupspec = $nsgroupsvc.Help.create.ns_group.Create()&lt;BR /&gt;$nsgroupmemberspec = $nsgroupsvc.Help.create.ns_group.membership_criteria.Element.NS_group_simple_expression.Create()&lt;BR /&gt;$nsgroupspec.display_name = $nsgroupname&lt;BR /&gt;$nsgroupmemberspec.target_type = "VirtualMachine"&lt;BR /&gt;$nsgroupmemberspec.target_property= "name"&lt;BR /&gt;$nsgroupmemberspec.op ="EQUALS"&lt;BR /&gt;$nsgroupmemberspec.value= $VMs.Name&lt;BR /&gt;$nsgroupspec.membership_criteria.Add($nsgroupmemberspec)&lt;BR /&gt;$nsgroupsvc.create($nsgroupspec)&lt;/P&gt;&lt;P&gt;The Security Group is successfully created for me, but I can only see it in Manager Mode and not in Policy Mode in NSX-T Manager UI.&amp;nbsp;What needs to be changed to see SG also in Policy Mode?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 10:36:31 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963837#M111549</guid>
      <dc:creator>ggovek</dc:creator>
      <dc:date>2023-04-14T10:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create NSX-T Security Groups with PowerCLI</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963839#M111550</link>
      <description>&lt;P&gt;Looks like the method creates the group in Manager mode.&lt;BR /&gt;Afaik VMW advises not to mix both modes for creating objects, see&amp;nbsp;&lt;A href="https://docs.vmware.com/en/VMware-NSX-T-Data-Center/3.2/installation/GUID-BB26CDC8-2A90-4C7E-9331-643D13FEEC4A.html" target="_blank" rel="noopener"&gt;When to Use Policy Mode or Manager Mode&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Btw, this Get-NsxtService cmdlet is deprecated.&lt;BR /&gt;You should use the cmdlets in the&amp;nbsp;&lt;SPAN&gt;VMware.Sdk.Nsx.Policy module.&lt;BR /&gt;See an excellent write-up on the subject in&amp;nbsp;&lt;A href="https://blog.redlogic.nl/en/powercli-13-create-nsx-security-groups" target="_blank" rel="noopener"&gt;PowerCli 13 Create NSX Security Groups&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 11:07:16 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963839#M111550</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2023-04-14T11:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create NSX-T Security Groups with PowerCLI</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963870#M111553</link>
      <description>&lt;P&gt;Thanks for the advice. It works for Local Managers, code is Bellow:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Could someone help me with how I could create Security Groups on the Global Manager?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 14:07:54 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2963870#M111553</guid>
      <dc:creator>ggovek</dc:creator>
      <dc:date>2023-04-14T14:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create NSX-T Security Groups with PowerCLI</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2964115#M111575</link>
      <description>&lt;P&gt;I found a solution and changed only this command:&lt;/P&gt;&lt;PRE&gt;$createdGroup = Invoke-PatchGroupForDomain -Server $n -DomainId default -Group $group -GroupId $GroupName&lt;/PRE&gt;&lt;P&gt;to&lt;/P&gt;&lt;PRE&gt;$createdGroup = Invoke-GlobalInfraPatchGroupForDomain -Server $n -DomainId default -Group $group -GroupId $GroupName&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With&amp;nbsp;Get-Command -Module VMware.Sdk.Nsx.Policy&amp;nbsp;we get all the necessary commands for NSX Module.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Apr 2023 11:51:19 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Create-NSX-T-Security-Groups-with-PowerCLI/m-p/2964115#M111575</guid>
      <dc:creator>ggovek</dc:creator>
      <dc:date>2023-04-17T11:51:19Z</dc:date>
    </item>
  </channel>
</rss>

