<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sikku1994 on Medium]]></title>
        <description><![CDATA[Stories by Sikku1994 on Medium]]></description>
        <link>https://medium.com/@sikkumishra1994?source=rss-1c2eaa8115a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Sikku1994 on Medium</title>
            <link>https://medium.com/@sikkumishra1994?source=rss-1c2eaa8115a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:05:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sikkumishra1994/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automating HA enabled HCX Network Extensions with PowerShell]]></title>
            <link>https://medium.com/@sikkumishra1994/automating-ha-enabled-hcx-network-extensions-with-powershell-792cb7dad816?source=rss-1c2eaa8115a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/792cb7dad816</guid>
            <category><![CDATA[hcx]]></category>
            <category><![CDATA[vmware-esxi]]></category>
            <category><![CDATA[vmware-vsphere]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Sikku1994]]></dc:creator>
            <pubDate>Mon, 14 Oct 2024 12:42:53 GMT</pubDate>
            <atom:updated>2024-10-14T12:45:40.108Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, I’ll walk you through a PowerShell script that automates the process of extending networks in VMware HCX. This script reads configuration data from a JSON file and uses it to configure network extensions between source and destination sites. Let’s dive into the details!</p><h3>Prerequisites</h3><p>Before you begin, ensure you have the following:</p><ul><li>Access to the HCX server.</li><li>PowerShell installed on your machine.</li><li>A JSON file (Networklist.json) containing the network configuration details.</li></ul><h3>Input JSON Format</h3><p>To use this script effectively, you need a JSON file (Networklist.json) with the following structure:</p><p>JSON</p><pre>[<br>    {<br>        &quot;source_Name&quot;: &quot;source-hcx-server.example.com&quot;,<br>        &quot;destination_Name&quot;: &quot;destination-vcenter.example.com&quot;,<br>        &quot;sourceNetwork_Name&quot;: &quot;Source-Network-Name&quot;,<br>        &quot;sourceAppliance_Name&quot;: &quot;Source-Appliance-Name&quot;,<br>        &quot;networkGatewayIP&quot;: &quot;192.168.1.1&quot;,<br>        &quot;networkGatewaySubnetMask&quot;: &quot;255.255.255.0&quot;,<br>        &quot;haGroupName&quot;: &quot;HA-Group-Name&quot;,<br>        &quot;destinationGatewayName&quot;: &quot;Destination-Gateway-Name&quot;,<br>        &quot;sourceNetwork_isNsxT&quot;: true,<br>        &quot;destinationNetwork_isNsxT&quot;: true,<br>        &quot;allowOverlappingVLAN&quot;: true<br>    }<br>]</pre><h3>Default Values</h3><p>The script uses default values for several boolean variables unless specified otherwise in the JSON file. By default, these variables are set to $false:</p><ul><li>sourceNetwork_isDistributedRouter</li><li>sourceNetwork_trunkMode</li><li>sourceNetwork_isNsxT</li><li>destinationNetwork_isDistributedRouter</li><li>destinationNetwork_trunkMode</li><li>destinationNetwork_isNsxT</li><li>features_proximityRouting</li><li>features_egressOptimization</li><li>features_mobilityOptimizedNetworking</li><li>allowOverlappingVLAN</li></ul><p>These defaults ensure that the script can handle cases where certain properties are not explicitly defined in the input JSON, making it robust and flexible. This way, you can focus on specifying only the necessary details, and the script will take care of the rest.</p><h3>The Script</h3><p>Here’s the PowerShell script that performs the network extension:</p><pre>param (<br>    [string]$HCXServerIP,<br>    [string]$HCXUsername,<br>    [string]$HCXPassword,<br>    [string]$Path<br>)<br><br>function Get-JsonData {<br>    param (<br>        [string]$Path<br>    )<br>    return Get-Content -Path $Path | ConvertFrom-Json<br>}<br><br>function Connect-ToHCXServer {<br>    param (<br>        [string]$ServerIP,<br>        [string]$Username,<br>        [string]$Password<br>    )<br>    return Connect-HCXServer -Server $ServerIP -User $Username -Password $Password<br>}<br><br>function Get-AuthToken {<br>    param (<br>        [string]$TokenURL,<br>        [string]$Username,<br>        [string]$Password<br>    )<br>    $tokenHeaders = @{<br>        &quot;Accept&quot; = &quot;application/json&quot;<br>        &quot;Content-Type&quot; = &quot;application/json&quot;<br>    }<br>    $tokenBody = @{<br>        &quot;username&quot; = $Username<br>        &quot;password&quot; = $Password<br>    } | ConvertTo-Json<br>    $tokenResponse = Invoke-WebRequest -Uri $TokenURL -Method Post -Headers $tokenHeaders -Body $tokenBody<br>    return $tokenResponse.Headers[&quot;x-hm-authorization&quot;]<br>}<br><br>function Get-HAGroupId {<br>    param (<br>        [string]$HAGroupURL,<br>        [string]$Token,<br>        [string]$HAGroupName<br>    )<br>    $haGroupHeaders = @{<br>        &quot;accept&quot; = &quot;application/json&quot;<br>        &quot;x-hm-authorization&quot; = $Token<br>    }<br>    $haGroupresponse = Invoke-WebRequest -Uri $HAGroupURL -Method Get -Headers $haGroupHeaders<br>    $haGroupresponseJson = $haGroupresponse.Content | ConvertFrom-Json<br>    foreach ($item in $haGroupresponseJson.items) {<br>        if ($item.name -eq $HAGroupName) {<br>            return $item.groupId<br>        }<br>    }<br>}<br><br>function Extend-Network {<br>    param (<br>        [string]$NetworkExtensionURL,<br>        [string]$Token,<br>        [hashtable]$Body<br>    )<br>    $networkExtensionHeaders = @{<br>        &quot;Accept&quot; = &quot;application/json&quot;<br>        &quot;x-hm-authorization&quot; = $Token<br>        &quot;Content-Type&quot; = &quot;application/json&quot;<br>    }<br>    $networkExtensionbody = $Body | ConvertTo-Json<br>    return Invoke-WebRequest -Uri $NetworkExtensionURL -Method Post -Headers $networkExtensionHeaders -Body $networkExtensionbody<br>}<br><br>$jsonData = Get-JsonData -Path $Path<br>$connection = Connect-ToHCXServer -ServerIP $HCXServerIP -Username $HCXUsername -Password $HCXPassword<br>[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }<br><br>try {<br>    foreach ($item in $jsonData) {<br>        # Variable declaration<br>        $source_Name = $item.source_Name<br>        $destination_Name = $item.destination_Name<br>        $sourceNetwork_Name = $item.sourceNetwork_Name<br>        $sourceAppliance_Name = $item.sourceAppliance_Name<br>        $networkGatewayIP = $item.networkGatewayIP<br>        $networkGatewaySubnetMask = $item.networkGatewaySubnetMask<br>        $haGroupName = $item.haGroupName<br>        $destinationGatewayName = $item.destinationGatewayName<br><br>        $tokenURL = &quot;https://$source_Name/hybridity/api/sessions&quot;<br>        $haGroupURL = &quot;https://$source_Name/hybridity/api/interconnect/appliances/ha/groups&quot;<br>        $networkExtensionURL = &quot;https://$source_Name/hybridity/api/networkExtensions&quot;<br><br>        $source = Get-HCXSite -Source<br>        $destination = Get-HCXSite -Destination -Name $destination_Name<br>        $sourceNetwork = Get-HCXNetwork -Name $sourceNetwork_Name<br>        $destinationNetworkgateway = Get-HCXGateway -DestinationSite $destination -Name $destinationGatewayName<br>        $sourceAppliance = Get-HCXAppliance -Name $sourceAppliance_Name<br><br>        $source_endpointID = $source.EndpointId<br>        $source_resourceID = $source.Id<br>        $source_EndpointType = $source.EndpointType<br>        $source_Type = $source.Type<br>        $source_EndpointName = $source.EndpointName<br>        $source_Name = $source.Name<br><br>        $destination_endpointID = $destination.EndpointId<br>        $destination_resourceID = $destination.Id<br>        $destination_EndpointType = $destination.EndpointType<br>        $destination_Type = $destination.Type<br>        $destination_EndpointName = $destination.EndpointName<br>        $destination_Name = $destination.Name<br><br>        $sourceNetwork_Name = $sourceNetwork.Name<br>        $sourceNetwork_Type = $sourceNetwork.Type<br>        $sourceNetwork_Id = $sourceNetwork.Id<br>        $sourceNetwork_isDistributedRouter = if ($null -eq $item.sourceNetwork_isDistributedRouter) { $false } else { $item.sourceNetwork_isDistributedRouter }<br>        $sourceNetwork_trunkMode = if ($null -eq $item.sourceNetwork_trunkMode) { $false } else { $item.sourceNetwork_trunkMode }<br>        $sourceNetwork_isNsxT = if ($null -eq $item.sourceNetwork_isNsxT) { $false } else { $item.sourceNetwork_isNsxT }<br><br>        $destinationNetworkgateway_Id = $destinationNetworkgateway.Id<br>        $destinationNetworkgateway_Name = $destinationNetworkgateway.Name<br>        $destinationNetwork_isDistributedRouter = if ($null -eq $item.destinationNetwork_isDistributedRouter) { $false } else { $item.destinationNetwork_isDistributedRouter }<br>        $destinationNetwork_trunkMode = if ($null -eq $item.destinationNetwork_trunkMode) { $false } else { $item.destinationNetwork_trunkMode }<br>        $destinationNetwork_isNsxT = if ($null -eq $item.destinationNetwork_isNsxT) { $false } else { $item.destinationNetwork_isNsxT }<br><br>        $sourceAppliance_Id = $sourceAppliance.Id<br>        $sourceAppliance_Type = $sourceAppliance.Type<br>        $sourceAppliance_Name = $sourceAppliance.Name<br><br>        $features_proximityRouting = if ($null -eq $item.features_proximityRouting) { $false } else { $item.features_proximityRouting }<br>        $features_egressOptimization = if ($null -eq $item.features_egressOptimization) { $false } else { $item.features_egressOptimization }<br>        $features_mobilityOptimizedNetworking = if ($null -eq $item.features_mobilityOptimizedNetworking) { $false } else { $item.features_mobilityOptimizedNetworking }<br><br>        $allowOverlappingVLAN = if ($null -eq $item.allowOverlappingVLAN) { $false } else { $item.allowOverlappingVLAN }<br><br>        $token = Get-AuthToken -TokenURL $tokenURL -Username $HCXUsername -Password $HCXPassword<br>        $haGroupId = Get-HAGroupId -HAGroupURL $haGroupURL -Token $token -HAGroupName $haGroupName<br><br>        $networkExtensionbody = @{<br>        &quot;gateway&quot; = &quot;$networkGatewayIP&quot;<br>        &quot;netmask&quot; = &quot;$networkGatewaySubnetMask&quot;<br>        &quot;source&quot; = @{<br>            &quot;endpointId&quot; = &quot;$source_endpointID&quot;<br>            &quot;resourceId&quot; = &quot;$source_resourceID&quot;<br>            &quot;endpointType&quot; = &quot;$source_EndpointType&quot;<br>            &quot;resourceType&quot; = &quot;$source_Type&quot;<br>            &quot;endpointName&quot; = &quot;$source_EndpointName&quot;<br>            &quot;resourceName&quot; = &quot;$source_Name&quot;<br>        }<br>        &quot;destination&quot; = @{<br>            &quot;endpointId&quot; = &quot;$destination_endpointID&quot;<br>            &quot;resourceId&quot; = &quot;$destination_resourceID&quot;<br>            &quot;endpointType&quot; = &quot;$destination_EndpointType&quot;<br>            &quot;resourceType&quot; = &quot;$destination_Type&quot;<br>            &quot;endpointName&quot; = &quot;$destination_EndpointName&quot;<br>            &quot;resourceName&quot; = &quot;$destination_Name&quot;<br>        }<br>        &quot;sourceNetwork&quot; = @{<br>            &quot;networkId&quot; = &quot;$sourceNetwork_Id&quot;<br>            &quot;networkType&quot; = &quot;$sourceNetwork_Type&quot;<br>            &quot;networkName&quot; = &quot;$sourceNetwork_Name&quot;<br>            &quot;isDistributedRouter&quot; = $sourceNetwork_isDistributedRouter<br>            &quot;trunkMode&quot; = $sourceNetwork_trunkMode<br>            &quot;isNsxT&quot; = $sourceNetwork_isNsxT<br>        }<br>        &quot;destinationNetwork&quot; = @{<br>            &quot;gatewayId&quot; = &quot;$destinationNetworkgateway_Id&quot;<br>            &quot;gatewayName&quot; = &quot;$destinationNetworkgateway_Name&quot;<br>            &quot;isDistributedRouter&quot; = $destinationNetwork_isDistributedRouter<br>            &quot;trunkMode&quot; = $destinationNetwork_trunkMode<br>            &quot;isNsxT&quot; = $destinationNetwork_isNsxT<br>        }<br>        &quot;sourceAppliance&quot; = @{<br>            &quot;applianceId&quot; = &quot;$sourceAppliance_Id&quot;<br>            &quot;applianceName&quot; = &quot;$sourceAppliance_Name&quot;<br>            &quot;applianceType&quot; = &quot;$sourceAppliance_Type&quot;<br>        }<br>        &quot;features&quot; = @{<br>            &quot;proximityRouting&quot; = $features_proximityRouting<br>            &quot;egressOptimization&quot; = $features_egressOptimization<br>            &quot;mobilityOptimizedNetworking&quot; = $features_mobilityOptimizedNetworking<br>        }<br>        &quot;haGroupId&quot; = &quot;$haGroupId&quot;<br>        &quot;allowOverlappingVLAN&quot; = $allowOverlappingVLAN<br>    }<br>    }<br>} catch {<br>    Write-Output (&quot;An error occurred in the foreach block: &quot; + $_.Exception.Message)<br>}<br><br>if ($sourceNetwork_Id) {<br>    $extendedNetworks = Get-HCXNetworkExtension 2&gt;$null<br>    $isNetworkExtended = $extendedNetworks | Where-Object { $_.Network -Like $sourceNetwork_Name }<br><br>    if (!$isNetworkExtended) {<br>        $success = $false<br>        try {<br>            Write-Output (&quot;Creating extension request for network $sourceNetwork_Name !!&quot;)<br>            <br>            $networkExtensionresponse = Extend-Network -NetworkExtensionURL $networkExtensionURL -Token $token -Body $networkExtensionBody<br>            <br>            Write-Output (&quot;Extension request for $sourceNetwork_Name submitted Successfully !!&quot;)<br>        } catch {<br>            Write-Output (&quot;An error occurred while submitting the extension request: &quot; + $_.Exception.Message)<br>        }<br>    } else {<br>        Write-Output (&quot;Network $sourceNetwork_Name is already extended.&quot;)<br>    }<br>}</pre><ol><li><strong>Functions</strong>: The script is modularized into functions for better readability and reusability:</li></ol><ul><li>Get-JsonData: Reads and converts JSON data from a file.</li><li>Connect-ToHCXServer: Connects to the HCX server.</li><li>Get-AuthToken: Fetches an authentication token.</li><li>Get-HAGroupId: Retrieves the HA group ID based on the group name.</li><li>Extend-Network: Sends a POST request to extend the network.</li></ul><p><strong>2. Main Script</strong>:</p><ul><li>Reads JSON data and connects to the HCX server.</li><li>Iterates through each item in the JSON data to configure network extensions.</li><li>Fetches the authentication token and HA group ID.</li><li>Checks if the network is already extended and, if not, submits an extension request.</li></ul><h3>Conclusion</h3><p>This script simplifies the process of extending networks in VMware HCX by automating repetitive tasks. By using PowerShell and JSON, you can efficiently manage network extensions, saving time and reducing the potential for errors.</p><p>Feel free to customize the script to fit your specific needs and environment. Happy automating!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=792cb7dad816" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>