Power(Shell,CLI,NSX)

NSX-V: Create Logical Switches, Distributed Firewall Sections and Rules based on existing portgroup/vlans

In my previous blog post I wrote about how to automate the Enable MAC learning function on a VMware NSX Logical Switch via Powershell/PowerNSX. In this post I referred to a script which I used to export the configuration of the portgroup/vlans that where currently existing in the environment. I’m writing this blogpost, to share the script because someone might have a use case for it (more…)

Automate ‘Enable MAC Learning’ on Logical Switch with PowerNSX

I was working on a project at a customer where we needed to create Logical Switches, DFW rules and sections based upon all the current portgroups of all the environments. Because we are talking about +/- 400 logical switches which need to be created, this is not a job that you want to do via the vSphere Web Client. Therefore I created a script which exported all the current portgoup names and vlan configurations to CSV file. This CSV file is used to import all the stuff.

(more…)

Automate ESXi host provisioning

My last blog post was about automation of adding VMkernel adapters in a specific TCP/IP netstack. As I already mentioned in that post I was working on a script that will automate the whole process  of adding a host in vCenter, configure all the necessary stuff and bring it up to date with the configured VUM baseline(s).

The script itself containts PowerCLI commands and esxcli (v2) commands via the PowerCLI module. I tested this script successfully with the following versions:

(more…)

Cross vCenter vMotion between two identically named SSO domains with PowerCLI

This weekend i was playing around in my home lab and wanted to try the Cross vCenter vMotion functionality to a vCenter server in a different SSO domain with an identical SSO domain name.

Source:
vcenter.wesleygeelhoed.local (SSO DomainA: vsphere.local) (vCenter 6.5 U1)
Destination:
vcenter2.wge.corp (SSO DomainB: vsphere.local) (vCenter 6.5 U1)

As you can see the names of the SSO domains are identically, but in fact they are really two different SSO domains with each having their own VCSA with embedded PSC.

*the two vCenter instances are having a L3 connection over an IPsec VPN 

The script that I used with PowerCLI:

####################################################################################
# Variables
####################################################################################
# vCenter Source Details (SSO Domain A)
$SrcvCenter = ‘vcenter.wesleygeelhoed.local’
$SrcvCenterUserName = ‘administrator@vsphere.local’
$SrcvCenterPassword = ‘*********’
# vCenter Destination Details (SSO Domain B)
$DstvCenter = ‘vcenter2.wge.corp’
$DstvCenterUserName = ‘administrator@vsphere.local’
$DstvCenterPassword = ‘*********’
# vMotion Details
$vmToMigrate = ‘SRVCTX01’ # The VM Name to migrate
$DstDatastore = ‘ESX03-SSD’ # The destination datastore
$DstCluster = ‘DR’ # The destination cluster
$DstPortGroup = ‘vxw-dvs-18-universalwire-12-sid-10002-VXLAN’ # The port group or distributed port group.
####################################################################################
# Function GetPortGroupObject
function GetPortGroupObject {
Param(
[Parameter(Mandatory=$True)]
[string]$PortGroup
)
if (Get-VDPortGroup -Name $DstPortGroup -ErrorAction SilentlyContinue) {
return Get-VDPortGroup -Name $DstPortGroup
}
else {
if (Get-VirtualPortGroup -Name $DstPortGroup -ErrorAction SilentlyContinue) {
return Get-VirtualPortGroup -Name $DstPortGroup
}
else {
Write-Host “The PorGroup ‘$DstPortGroup’ doesn’t exist in the destination vCenter”
exit
}
}
}
function Drawline {
for($i=0; $i -lt (get-host).ui.rawui.buffersize.width; $i++) {write-host -nonewline -foregroundcolor cyan “-“}
}
####################################################################################
# Connect to vCenter Servers
Connect-ViServer -Server $SrcvCenter -User $SrcvCenterUserName -Password $SrcvCenterPassword -WarningAction Ignore | out-null
write-Host -foregroundcolor Yellow “`nConnected to Source vCenter…”
Connect-ViServer -Server $DstvCenter -User $DstvCenterUserName -Password $DstvCenterPassword -WarningAction Ignore | out-null
write-Host -foregroundcolor Yellow “Connected to Destination vCenter…”
####################################################################################
# vMotion 🙂
$vm = Get-VM $vmToMigrate
$destination = Get-VMHost -Location $DstCluster | Select-Object -First 1
$networkAdapter = Get-NetworkAdapter -VM $vmToMigrate
$destinationPortGroup = GetPortGroupObject -PortGroup $DstPortGroup
$destinationDatastore = Get-Datastore $DstDatastore
$vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore | out-null
####################################################################################
# Display VM information after vMotion
write-host -foregroundcolor Cyan “`nVM is now running on:”
Drawline
Get-VM $vmToMigrate | Get-NetworkAdapter | Select-Object @{N=”VM Name”;E={$_.Parent.Name}},@{N=”Cluster”;E={Get-Cluster -VM $_.Parent}},@{N=”ESXi Host”;E={Get-VMHost -VM $_.Parent}},@{N=”Datastore”;E={Get-Datastore -VM $_.Parent}},@{N=”Network”;E={$_.NetworkName}} | Format-List
####################################################################################
# Disconnect
Disconnect-VIServer -Server * -Force -Confirm:$false

2017-09-24 18_16_03-VMware PowerCLI 6.5 Release 1 build 4624819Executing script from the Powershell command prompt, no issues or warnings appear.

2017-09-24 18_16_45-vSphere Web Client

2017-09-24 18_17_08-srvvmm - Remote Desktop Connection

Normal tasks are created as expected in the source and destination vCenter server.

After some minutes the task was completed successfully and the VM was running normal and smooth in the same VXLAN network on the destination vCenter Server.

Many blog posts already exists on the internet about this topic, but mainly focused on SSO domains with different names. I just wanted to test if some weird behavior would appear if you used the same SSO domain names. And the answer is; no. The migration went as smooth as an internal vMotion.

Source: CloudManiac