When segment is creating on NSX-T Manager Web. Automatically ID and relative_path are created with GUID.
(Get-NsxtPolicyService -Name com.vmware.nsx_policy.infra.segments).list().results | Select-Object display_name, id, path, relative_path
display_name id path relative_path
------------ -- ---- -------------
Powershell_Seg01 7e091b41-4a6c-415a-99df-73d05b4895f4 /infra/segments/7e091b41-4a6c-415a-99df-73d05b4895f4 7e091b41-4a6c-415a-99df-73d05b4895f4
Powershell_Seg01 039f80c2-ccaf-405b-9001-296157776b26 /infra/segments/039f80c2-ccaf-405b-9001-296157776b26 039f80c2-ccaf-405b-9001-296157776b26
Powershell_Seg01 ca059dc0-8dd2-42de-bb12-4c613bc75400 /infra/segments/ca059dc0-8dd2-42de-bb12-4c613bc75400 ca059dc0-8dd2-42de-bb12-4c613bc75400
Powershell_Seg01 ca059dc0-8dd2-42de-bb12-4c613bc75401 /infra/segments/ca059dc0-8dd2-42de-bb12-4c613bc75401 ca059dc0-8dd2-42de-bb12-4c613bc75401
Seg1 Seg1 /infra/segments/Seg1 Seg1
Seg2 Seg2 /infra/segments/Seg2 Seg2
Seg3 Seg3 /infra/segments/Seg3 Seg3
Seg4 Seg4 /infra/segments/Seg4 Seg4
Seg5 Seg5 /infra/segments/Seg5 Seg5
seg123 seg123 /infra/segments/seg123 seg123
Manually segment ID must be input to use Powershell.
https://www.vrealize.it/2019/11/12/powercli-for-nsx-t-policy-api/#Create-Groups
#Variables for NSX Manager Connection
$nsxmanagerip = "IP_OR_DNS_NAME"
$nsxuser = "USERNAME"
$nsxpasswd = "PASSWORD"
#General Variables
$description = "Created with VMware PowerCLI"
$tag = "powercli"
#Variables for Segment
$segmentid = "SEGMENTNAME"
$transportzone = "/infra/sites/default/enforcement-points/default/transport-zones/TRANSPORTZONEID"
$path_to_t1_rtr = "/infra/tier-1s/T1ROUTERNAME"
$defaultgateway = "IP-ADDRESS/MASK"
#Connect to NSX Manager
Connect-NsxtServer -Server $nsxmanagerip -User $nsxuser -Password $nsxpasswd
#Retrieve Segment Information
$segmentdata = Get-NsxtPolicyService -Name com.vmware.nsx_policy.infra.segments
#Set Variables
$segmentdata = Get-NsxtPolicyService -Name com.vmware.nsx_policy.infra.segments
$segmentspecification = $segmentdata.Help.patch.segment.Create()
$segmentspecification.description = $description
$segmentspecification.id = $segmentid
$segmentspecification.transport_zone_path = $transportzone
$segmentspecification.connectivity_path = $path_to_t1_rtr
#Set Default Gateway Variables
$subnetSpec = $segmentdata.help.patch.segment.subnets.Element.Create()
$subnetSpec.gateway_address = $defaultgateway
$segmentspecification.subnets.Add($subnetSpec) | Out-Null
#Add Tag to the Segment
$segmenttag = $segmentdata.help.patch.segment.tags.Element.Create()
$segmenttag.tag = $tag
$segmentspecification.tags.Add($segmenttag) | Out-Null
#Create Segment
$segmentdata.patch($segmentid, $segmentspecification)
How do you think about the ID and relative_path are created by "[guid]::NewGuid()"?
Should NSX-T segment ID, relative_path created with GUID?
$segmentid = [guid]::NewGuid()
$display_name = "Seg01"