Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Microsoft Powershell: Windows 2016 Install and configure NFS server

December 16, 2017 04:51PM

Useful Links
Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux
VMWare ESXi add and create NFS datastore
Mount NFS share to multiple ESXi hosts
Unmount NFS datastores from VMware ESXi and NFS is in use

Here I will use Powershell cmdlets to install and configure NFS server on windows server. Same task I have implemented previously using graphical user interface - Server Manager as shown in above links. Here on the windows server 2016 open Powershell as an Administrator. To list the required NFS server role, Use below cmdlet, Make the note of install state its available.
Get-WindowsFeature *nfs*

Next command installs NFS server with including all required sub features and management tools. Use Name from previous result.
Install-WindowsFeature FS-NFS-Service -IncludeAllSubFeature -IncludeManagementTools

Microsoft Windows NFS server Powershell Get-WindowsFeature, Install-windowsFeature, fs-nfs-service, Powershell automation

This installation doesn't require restart, exit code is success and success is true. Next create NFS share, I have already created folder on c:\nfs01.

New-NfsShare -Name 'nfs01' -Path 'C:\nfs01' -EnableUnmappedAccess $True -Authentication sys

Microsoft Windows NFS server Powershell Get-WindowsFeature, Install-windowsFeature, fs-nfs-service, automation New-NFSshare, file share, network file system, authentication sys, enable unmapped access.png

Warning: Windows NFS server is not listed on VMWare HCL as Esxi NFS datastore. I am using it as a demo purpose.

Once NFS share is created, It needs to assign share permissions, here I am adding Esxi servers with read/write and root access. Name should be nfs share name from previous result. I am adding one by one changing ClientName.

Grant-NfsSharePermission -Name 'nfs01' -ClientName 'Esxi001.vcloud-lab.com' -ClientType 'Host' -Permission 'readwrite' -AllowRootAccess:$true
Grant-NfsSharePermission -Name 'nfs01' -ClientName 'Esxi002.vcloud-lab.com' -ClientType 'Host' -Permission 'readwrite' -AllowRootAccess:$true

Microsoft Windows NFS server Powershell mount nfs share, Grant-NfsSharePermission, Install-windowsFeature, permission readwrite, allowrootaccess, automation New-NFSshare, network file system, authentication sys.png

Here NFS server is installed and configured successfully, Created NFS Share and allocated permissions using Powershell, If you want to check the existing shares and configured permissions, use below cmdlets.

Get-NfsShare
Get-NfsSharePermission

Microsoft Windows NFS server Powershell Get-WindowsFeature, Install-windowsFeature, Get-NfsSharePermission, automation Get-NFSshare, file share, network file system, authentication sys, enable unmapped access.png

Unmount NFS datastores from VMware ESXi and NFS is in use

December 10, 2017 01:53PM

Mounting NFS datastore on ESXi server is very easy, similar way you might need to remove/unmount NFS share from ESXi server for maintenance or migration purpose. To unmount it, open VMWare vSphere Web Client and select Storage tab, from the list select NFS datastore, right click on it and select Unmount datastore. This launches the wizard, In the wizard the datastore is accessible from the hosts listed in the list. The host(s) will no longer have access to the virtual machine files on this datastore once the access is removed. If the datastore is unmounted from all hosts it will disappear from the inventory. Select the hosts that should not have access to this datastore. Click the check box on hosts list, and OK to proceed.

Warning: If you have configured HA cluster while unmounting datastore make sure, NFS datastore might be used by vSphere HA for heartbeating. Once unmounted, check the 'Cluster-Monitor-Issues' page to see if any hosts now have an insufficient number of heartbeat datastores. 

Earlier useful posts
Mount NFS share to multiple ESXi hosts
VMWare ESXi add and create NFS datastore
Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux
Unmount NFS datastores from VMware ESXi and NFS is in use

vmware vsphere web client, esxi vcenter, unmount datastore, nfs, network file system, select hosts to remove nfs, nfs storage, share drive

Next if unmounting NFS datastore shows the error The resource 'nfs' is in use (The "remove datastore" operation failed for the entity with the following error message), to resolve this, make sure that the following prerequisites are met:

  • No virtual machines reside on the datastore.
  • The datastore is not managed by Storage DRS.
  • The datastore is not part of a datastore cluster.
  • The datastore is not used for vSphere HA heartbeating.
  • Storage I/O control is disabled for this datastore.

vmware esxi, vcenter vsphere web client, NFs unmount datastore, the resource nfs is in use, network file system, error unmounting

In my case NFS storage still had virtual machines running, which I migrated using storage vmotion to another drive and emptied nfs drive, also made sure there are no other  dependencies listed above, After that removing NFS was successful with no error.

vmware vsphere web client nfs in use by virtual machine, mount NFS, unmount NFS, network file system, remove datastore from esxi, mount nfs vmfs datastore

Useful Article
MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV
VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE
VMWARE ESXI INSTALL AND CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER FOR VMFS VERSION 6 DATASTORE
VMWARE VCENTER STORAGE MIGRATE/SVMOTION VM AND PORT BINDING MULTIPATHING TESTING
MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV 

Mount NFS share to multiple ESXi hosts

December 9, 2017 07:56PM

"A datastore with the same name and backing configuration already exists in the current datacenter. Change the datastore name and backing configuration to continue."

While adding NFS datastore on esxi server I saw above error. This NFS drive was already added on the Esxi001 successfully, but when tried to add to another Esxi002 using add datastore wizard I was keep getting error and not allowed to add it. Just for your information when you add VMFS datastore, it is by default added and mounted to all other configured esxi servers. But for NFS datastore you need to mount it on each esxi host separately. 

Check earlier article to view VMWare ESXi add and create NFS datastore.

vmware vsphere web client esxi, vcenter, configure datastore, nfs, network file system, add datastore nfs failed, to current datacenter configuration, vmfs

For resolution you have to mount NFS datastore once to any of one ESXi server in the cluster, once it is added, go the datastores view, from the list select NFS datastore, Right click on it, Click Mount Datastore to Additional Hosts. In the wizard, it shows the list of esxi host where this datastore is not mounted. Click on the host to mount and click OK.

vmware esxi, vsphere, web client, vcenter, mount datastore, nfs, network file system, add nfs additional hosts, esxi

To confirm NFS is mounted correctly, you can browse datastores in esxi host or in the datastores tab view, check the Hosts tab.

vmware vsphere web client esxi, vcenter, nfs, network file system file system on esxi, nfs datastores, mount nfs esxi to additional host, vmfs datastore, storage

Useful Article
Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux
MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV
VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE
VMWARE ESXI INSTALL AND CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER FOR VMFS VERSION 6 DATASTORE
VMWARE VCENTER STORAGE MIGRATE/SVMOTION VM AND PORT BINDING MULTIPATHING TESTING
MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV
Unmount NFS datastores from VMware ESXi and NFS is in use
Microsoft Powershell: Windows 2016 Install and configure NFS server

VMWare ESXi add and create NFS datastore

December 9, 2017 12:55PM

In the earlier article Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux, I shown on installing and configuring NFS server on Microsoft Windows 2016 sever. NFS datastores is one of the file type of datastore to keep virtual machines on VMWare Esxi server, This is also good options to keep ISO and VM templates, NFS datastores can be very economical for the this purpose, it is also capable of running Production environment. NFS protocol uses existing IP TCP/IP based network protocol and it is relatively easy to design and deployment. With high performance supported storage on VMware HCL and 10 Gig network cards you can run high IOPs required applications and VMs without any issues.

Warning: Windows NFS server is not listed on VMWare HCL as Esxi NFS datastore. I am using it as a demo purpose.

There are two types datastores filesystem supported on VMWare Esxi, VMFS and NFS. NFS file system protocol is very handy and supports some of the below notable features.

  • VMware DRS and VMware HA
  • Virtual machine snapshots
  • vMotion
  • ISO images, which are presented as CD-ROMs to virtual machines

I have small diagram here, it shows how I have separate network path on Esxi to connect to NAS / NFS storage. 

nas, network area storage design, esxi, vmware, vsphere, vcenter, nfs, network file system, nas, mount datastore, nfs share folder

Related Article
MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV
Microsoft Powershell: Windows 2016 Install and configure NFS server

I use NFS datastore to mainly store ISO images and templates (On tier 3 drives), also use it when migrating Virtual Machines between at Esxi located at different location, Once svmotion vm to NFS datastores, data or VMs are easily portable by mounting NFS datastores to another ESXi. If NFS is on portable small NAS device it makes very easy to task get done by shipping devices and NFS doesn't require any extra configuration. Configuring NFS datastore on Esxi requires VMKernel portgroup to be exist, The VMkernel TCP/IP stack handles iSCSI, NFS, and vMotion. I have already written one article to configure VMkernel portgroup for Iscsi, but can be used here as well --> VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE

In the VMWare vSphere Web Client, Select ESXi server, go to Configure tab, Select Datastores from list, Click on Create a new datastore. This opens new datastore wizard.

vmware vsphere esxi, configure datastores, create a new datastore, Microsoft windows NFS share add to esxi, Network file system esxi, linux

In the New Datastore wizard, select and specify datastore type NFS (Create an NFS datastore on an NFS share over the network).

vmware vsphere esxi vcenter, add new datastore, NFS, microsoft windows network file system, NFS datastore, disk lun

Select NFS 3 version, make sure you use only one NFS version to access a given datastore. Consequences of mounting one or more hosts to the same datastore using different versions can include data corruption.

vmware vsphere esxi vcenter, add new datastore, NFS, microsoft windows network file system, NFS datastore, disk lun. NFS 3, linux nfs, network file system, vmware, esxi, vcenter, vspher datastore, vmfs, filesystem

In the Name and configuration, Specify datastore name, folder and server name to mount NFS datastore. Access mode should be Read/Write if it is intended to run Virtual machines. Also another thing is If you plan to configure an existing datastore on new hosts in the datacenter, it is recommended to use the "mount to additional hosts" action instead.

To view this information you can check earlier blog screenshot to view current NFS configuration.

vmware vsphere esxi vcenter, NFS, microsoft windows network file system, NFS datastore, disk lun. NFS 3, linux nfs, network file system,nfs datastore name, folder, server, nas, network access server, vmfs, filesystem.png

This is last step of configuration of New Datastore. In the Ready to complete page, review your settings selections before finishing the wizard.

vmware vsphere esxi vcenter, NFS, microsoft windows network file system, NFS datastore, disk lun. NFS 3, linux nfs access mode, nfs settings, network file system,nfs datastore name,nas, network access server, filesystem.png

Once Datastore is created successfully, it can be listed under Datastores. I have migrated one virtual machine to this NFS datastore to check everything is working, Once browsed it VM is located and I have correct access. Next contrary to VMFS datastore mount, you will have to mount NFS share on each esxi server individually and there is a separate procedure which can be found on Mount NFS share to multiple ESXi hosts.

esxi vmware, vsphere, vcenter, configure datastores NFS, network file system, browser datastore, NFS migrate svmotion, storage vmotion VM, virtual machine on NFS, NEtwork file system

Useful Article
VMWARE ESXI CONFIGURE (VSWITCH) VMKERNEL NETWORK PORT FOR ISCSI STORAGE
VMWARE ESXI INSTALL AND CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER FOR VMFS VERSION 6 DATASTORE
VMWARE VCENTER STORAGE MIGRATE/SVMOTION VM AND PORT BINDING MULTIPATHING TESTING
MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV
Unmount NFS datastores from VMware ESXi and NFS is in use

Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux

December 7, 2017 03:33PM

NFS (Network file system) is a distributed file sharing solution for diversified cross platform environments. It was originally designed to run on Sun solaris, This also supports and works well on windows and non-windows computers. NFS uses RPC and usually use Port (TCP and UDP) 111 and 2049. There are also ports for Cluster and client status (Port 1110 TCP for the former, and 1110 UDP for the latter) as well as a port for the NFS lock manager (Port 4045 TCP and UDP). In most of the environments NFS is configured in Linux as file share.

Warning: Windows NFS server is not listed on VMWare HCL as Esxi NFS datastore. I am using it as a demo purpose.

MICROSFOT WINDOWS 2012 R2 ISCSI TARGET STORAGE SERVER FOR ESXI AND HYPERV
Microsoft Powershell: Windows 2016 Install and configure NFS server

Here in this article I will setup one NFS server on Microsoft Windows server 2016. To install this role Open server manager, Click on Add roles and features (Manage). After clicking next on Add roles and features wizard with all default options, once you land on the Server Roles page, expand roles File and Storage services >> File and iSCSI Services and locate Server for NFS. Once you check the box it ask for for add features that are required for server for NFS, click Add features.

Microsoft, server manager, Add Roles and feature Wizard, file and storage services file and iscsi services, Server for NFS, File Services Tools, vCenter esxi nfs datastore mount.png

After clicks on next with keeping default options, finish the feature installation and configuration. It takes few minutes to complete setup.

In next article I have mounted this NFS drive on Esxi - Microsoft Windows 2016 Install and configure NFS server for ESXi and Linux and Mount NFS share to multiple ESXi hosts.

Microsoft, server manager, Add Roles and feature Wizard, file and storage services file and iscsi services, Server for NFS, File Services Tools, vCenter esxi nfs datastore mount, RSAT, Network file system linux on windows

After installing NFS server role successfully, Its time to configure new NFS Share, for configuration go to Server Manager, then File and Storage Services,  on the Shares box, Click Tasks from drop down box click New Share. This launches New share wizard. On the right side It gives me insight about volumes with drive space and I can plan for creating shares.

Server Manager, File and Storage Services Shares, NFS, network file system microsoft server, new nfs share, CIFS, smb, Microsoft windows NFS server for ESXI, vmware and linux.png

On the New share Wizard, Select the NFS Share - Quick Profile for this share. This describes as The basic profile represents the fastest way to create a NFS file share, typically used to share files with UNIX-based computers.

  • Suitable for general file sharing
  • Advanced options can be configured later by using properties dialog

Click next.

Microsoft, server manager, New share Wizard, file and storage services file and iscsi services, Server for NFS, NFS share - quick, File Services Tools, vCenter esxi nfs datastore mount.png

I have already created a folder on c:\nfs01. On the same path I will be creating NFS share. either browse and select the path or Type it under custom path.

Server Manager, select server and path for NFS share, network file system microsoft server, new nfs share, CIFS, smb, Microsoft windows NFS server for ESXI, vmware and linux, vsphere nfs mount

This is important stage of configuration, Provide the share name (I am keeping same as folder to avoid any confusion). Local path is c:\nfs01. Next note down Remote path to share. This will require in next articles. Generally this is a fqdn_Or_ip:/nfs01.

select server and path for NFS share, network file system microsoft server, local path, remote path, share name new nfs share wizard, CIFS, smb, Microsoft windows NFS server for ESXI, vmware and linux, vsphere nfs mount.png

On the No server authentication box specify the authentication methods that you want to use for this NFS share, check the boxes for No server authentication (AUTH_SYS), then Enable unmapped user access and select Allow unmapped user access by UID/GID. this will add require authentication while accessing servers.

Microsoft Windows NFS share, server new share wizard, for vmware esxi vcenter, Kerberos v5 authentication, integrity, privacy, krb5, server authetication auth_sys, unmapped user access uid, gid, anonymous access

The server evaluates the share permissions in the order they are shows below. the final access permissions on a file share are determined by taking into consideration both the share permission and the NTFS permission entries. the more restrictive permissions are then applied.

Click Add button to add permissions. In next articles I am using this blog to show how to add and mount same NFS share on esxi server as datastore. Next I will be adding esxi host fqdn or ip in Host, Share permissions should be selected to Read/Write, and check the box of Allow root access.

In next 

Microsoft Windows NFS share, server new share wizard, for vmware esxi vcenter, Kerberos v5 authentication, integrity, privacy, krb5, server authetication auth_sys, add permissions host, NTFS permissio, add host.png

Permissions to access the files on a share are set using a combination of folder permissions, share permissions, and, optionally, a central access policy. Next in the wizard, don't need to add or modify permissions, keep it default and press next.

Microsoft Windows NFS share, server new share wizard, for vmware esxi vcenter, Kerberos v5 authentication, Permissions and control access, read-write nfs, auth_sys, add permissions host, NTFS permissio, add host.png

On the Confirm Selections page verify all the settings are correct and click to create share.

Server Manager, Confirm selections share location, share properties network file system microsoft windows, NFS server on windows, vmware vsphere Esxi, nfs share mount

This takes few minutes (depending on the files in the folder) and check the progress and status of Create NFS share and set NFS permissions.

Microsoft, server manager, Add Roles and feature Wizard, NFS view  results, nfs share permissions, file and storage services file and iscsi services, Server for NFS, File Services Tools, vCenter esxi nfs datastore mount.png

Finally NFS share will be listed with protocol NFS and in the next if you need to add hosts in permissions list. Right click nfs share, go to properties and make the necessary changes for later use.

server manager, file and storage services, shares nfs , quota volume, vmware vsphere esxi, vcenter

Useful articles
VMWARE ESXI INSTALL AND CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER FOR VMFS VERSION 6 DATASTORE
POWERCLI VMWARE: CONFIGURE SOFTWARE ISCSI STORAGE ADAPTER AND ADD VMFS DATASTORE
POWERCLI: VIRTUAL MACHINE STORAGE MIGRATE/SVMOTION AND DATASTORE PORT BINDING MULTIPATHING
PART 1 : INSTALLING ESXI ON VMWARE WORKSTATION HOME LAB
Unmount NFS datastores from VMware ESXi and NFS is in use

VMware Powercli : Gather distributed virtual switch information to JSON file to migrate standard switch

December 4, 2017 11:48AM

I have already written complete series on how to migrate distributed virtual switch to Standard virtual switch which helps to move Esxi host from one vCenter to another vCenter server. As you should not remove Esxi directly with distributed switch from vCenter until you move it to standard virtual switch properly. If you do it, you will find everything is working fine at the networking end, but you cannot modify network and it is kind of broken, and recovering from it will be hectic, you can consider downtime as well. 

Part 1 VMware Powercli : Gather distributed virtual switch information to JSON file to migrate standard switch
Part 2 Copy or clone distributed virtual switch portgroups to standard switch portgroups - Powercli

In my earlier part series all the steps were performed using VMware vSphere Web Client, graphical user interface. This is good for few clusters and Esxi hosts for migration., but what if I need to migrate to standard switches on more than 100 clusters, and each cluster has at list 5 esxi host. It will be very time consuming task and if there are any errors in it complete day is screwed up.

Note: I wrote and built this script where each esxi host in cluster is connected to only one distributed virtual switch with 2 uplink physical network adapters, It has Two vmkernel adpaters (Management and vMotion) and all the VMs network are connected to this distributed portgroups. as below screenshots, This is the common configuration I have seen in most of the environment. If you have mismatch in configuration (ie: more than 2 uplink connected or more than 2 vmkernel adapters exist), script  will not collect correct information, Once information is gathered, it is stored in JSON file

vmware vsphere vcenter esxi, virtual switches configuration, dvswitch, virtual distibuted switch collect information, powercli, automation, gather information

Before migrating from DVSwitch to standard vSwitch I need to collect existing information. This database contains, connected physical network adapters uplinks esxi DVSwitch, VMKernel port and Virtual Machine network adapter configuration (connected PortGroup). This script only gathers information and save to JSON file and doesn't make any changes. 

To run script correctly use below article to setup your VMware PowerCLI environment. Make sure you have installed latest version of Powercli, read help in the scripts.
VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP
POWERCLI INITIALIZE-POWERCLIENVIRONMENT.PS1 CANNOT BE LOADED BECAUSE RUNNING SCRIPTS IS DISABLED

PS C:\Scripts> .\Get-VDswitchInfo.ps1 -vCenter vcsa65.vcloud-lab.com -Cluster Cluster01 -VDSwitch DVSwitch-NonProd-01 -JsonFile C:\Scripts\dvswitchInfo.json

Parameters Break-Down
-vCenter: vCenter parameter requires vCenter FQDN or IP to connect, this prompts for UserName and Password. 
-Cluster: Provide clustername for this parameter in the connected vCenter, Information will be fetched from Host withing this virtual cluster.
-VDSwitch: Esxi hosts within cluster, connected to this virtual distributed switch.
-JsonFile: Data is collected and stored in this JSON file.

vmware vsphere powercli, virtual distributed switch, get DVswitch information to JSON file, Migration from vDswitch to standard switch, cluster, vCenter, esxi

Earlier Series
Part 1 - Copy or clone distributed virtual switch portgroups to standard switch portgroups - Powercli
Migrating move back from Distributed virtual switch to Standard virtual switch - VMKernal Adapter - Part 2
Migrating move back from Distributed virtual switch to Standard virtual switch - VMs (Virtual Machine) - Part 3
Part 4: Remove ESXi Host from Distributed switch and migrate to virtual switch completely

Json file has complete network information as below and it is one of the industry standard to view and store data.

vmware vsphere powercli, Get-cluster, Get-VMhost, get-vdswitch, Get-Vdportgroup, get-vm, get-vmhost, get-networkadapter, vcenter, esxi, powershell, collect information to json, distributed switch standard switch

download vmware vsphere powercli, powershell, esxi, vcenter, distributed virtual switch, standard switch,  migration powercliDownload script.
This script is also available on GitHub.
 

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#requires -version 4
<#
.SYNOPSIS
    Collects vDSwitch (Distributed virtual switch) portgroups, Virtual machines and Physical Port infromation for migration.
.DESCRIPTION
    The Get-VDswitchInfo Collects existing virtual distributed switch information, This script is written for one dvswitch in a cluster, and 2 nics per esxi server. Here it collects info about EsxiHost, DVSwitch Physical Adapters, VMKernel adapters, Virtual Machine Network. This is information is useful in my next script when migrating from DvSwitch to Standard switch.
.PARAMETER vCenter
    Prompts you for vCenter server FQDN or IP address to connect, vc parameter is an alias, This value can be taken from pipline by property name. 
.PARAMETER Cluster
    Make sure you type a valid ClusterName within the provided vCenter server. This script collect information from this Cluster and host.
.PARAMETER DVSwitch
    This ask for existing distributed virtual switch (dvswitch) in the cluster.
.PARAMETER JsonFile
    Collected information is stored in JSON file, provide a path for json ie: c:\temp\vdinfo.json 
.INPUTS
    VMware.VimAutomation.ViCore.Impl.V1.Inventory.ClusterImpl
    VMware.VimAutomation.Vds.Impl.V1.VmwareVDSwitchImpl
    VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.VirtualPortGroupImpl
    VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.VirtualSwitchImpl
.OUTPUTS
    VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.VirtualPortGroupImpl
    VMware.VimAutomation.ViCore.Impl.V1.Host.Networking.VirtualSwitchImpl
.NOTES
  Version:        1.0
  Author:         Kunal Udapi
  Creation Date:  12 August 2017
  Purpose/Change: Collect dvswitch information to json file for DVswtich to SSwitch migration
  Useful URLs:    http://vcloud-lab.com/entries/powercli/copy-or-clone-distributed-virtual-switch-portgroups-to-standard-switch-portgroups-powercli
  OS Version:     Windows 10 pro version 1703, Build 15063.726
  Powershell:     5.1.15063.726  Desktop Edition
  Powercli:       VMware PowerCLI 6.5 Release 1 build 4624819
                  VMware VimAutomation Core PowerCLI Component 6.5 build 4624450
                  VMware Vds PowerCLI Component 6.5 build 4624695

.EXAMPLE
    PS C:\>.\Get-VDswitchInfo.ps1 -vCenter vcsa65.vcloud-lab.com -Cluster Cluster01 -VDSwitch DVSwitch-NonProd-01 -JsonFile c:\temp\dvswitchInfo.json

    This command connects vcenter 'vcsa65.vcloud-lab.com',  infCollectormation from 'DVSwitch-NonProd-01' and Cluster 'Cluster01' its esxi host, keep the information in c:\temp\dvswitchInfo.json file.
#>

[CmdletBinding(SupportsShouldProcess=$True,
    ConfirmImpact='Medium', 
    HelpURI='http://vcloud-lab.com', 
    SupportsTransactions=$True)]
Param (
    [parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true, HelpMessage='Type vCenter server IP or FQDN you want to connect')]
    [alias('vc')]
    [String]$vCenter,
    [parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true, ValueFromPipeline=$true, HelpMessage='Type valid Cluster Name within vCenter server')]
    [alias('c')]
    [String]$Cluster,
    [parameter(Position=2, Mandatory=$true, ValueFromPipelineByPropertyName=$true, HelpMessage='Type valid distributed virtual switch (dvswitch) name')]
    [alias('vds')]
    [String]$VDSwitch,
    [parameter(Position=3, Mandatory=$true, ValueFromPipelineByPropertyName=$true, HelpMessage='Type valid distributed virtual switch (dvswitch) name')]
    [alias('File')]
    [String]$JsonFile
)
Begin {
    if ( -not (Get-Module  vmware.vimautomation.core)) {
        Import-Module vmware.vimautomation.core
        Import-Module vmware.vimautomation.vds
    }

    if ($global:DefaultVIServers.Name -notcontains $vCenter) {
        try {
            Connect-VIServer $vCenter -ErrorAction Stop
        }
        catch {
            Write-Host $($Error[0].Exception) -ForegroundColor Red
            break
        }
    }

    $OverAllInfo = @()
} #Begin
Process {
    try {
        $ClusterInfo = Get-Cluster $Cluster -ErrorAction Stop
        $DvSwitchInfo = Get-VDSwitch -Name $VDSwitch -ErrorAction Stop
    }
    catch {
        Write-Host $($Error[0].Exception) -ForegroundColor Red
        break
    }

    $EsxiHosts = $ClusterInfo | Get-VMHost | Sort-Object Name
    foreach ($ESXi in $EsxiHosts) {
        $ESXiHostName = $ESXi.Name
        Write-Host "Collecting information from $ESXiHostName ..." -ForegroundColor Green
        try {
            $DistributedSwitch = $ESXi | Get-VDSwitch -Name $VDSwitch
        }
        catch {
            Write-Host $($Error[0].Exception) -ForegroundColor Red
            Continue
        }
        $vDSwitchName = $DistributedSwitch.Name

        $UplinkPortGroups = $DistributedSwitch | Get-VDPort -Uplink | Where-Object {$_.ProxyHost.Name -eq $ESXiHostName} | Sort-Object Name
        $PhysicalAdapters = $DistributedSwitch | Get-VMHostNetworkAdapter -Physical | Where-Object {$_.VMHost.Name -eq $ESXiHostName} | Sort-Object Name
        $VMKernelAdapters = $DistributedSwitch | Get-VMHostNetworkAdapter -VMKernel | Where-Object {$_.VMHost.Name -eq $ESXiHostName} | Sort-Object Name
        $VDPortGroup = $DistributedSwitch | Get-VDPortgroup 
        #$UPLinks = $VDPortGroup | Where-Object {$_.IsUplink -eq $true}
        
        if ($PhysicalAdapters.Count -lt 2) {
            Write-Host "No network redundancy found on server $ESXiHostName, do no proceed until you have 2 Nic cards..." -ForegroundColor Red
        } #if ($PhysicalAdapters.Count -lt 2)

        $PNicInfo = $UplinkPortGroups | Select-Object Name, ConnectedEntity, Switch, ProxyHost
    
        $CompleteVMKInfo = @()
        $VMKArray = @('Management', 'vMotion')
        foreach ($VMK in $VMKArray) {
            switch ($VMK) { 
                Management {
                    $SpecificVMK = $VMKernelAdapters | Where-Object {$_.ManagementTrafficEnabled -eq $true}
                } #Management {
                vMotion {
                    $SpecificVMK = $VMKernelAdapters | Where-Object {$_.VMotionEnabled -eq $true}
                } #vMotion
            } #switch ($VMK) {
        
            $VMKPortGroup = $VDPortGroup | Where-Object {$_.Name -eq $SpecificVMK.PortGroupName}
            $VMKVLanId = $VMKPortGroup.VlanConfiguration.VlanId
            $VMKInfo = [PSCustomObject]@{
                Name = $SpecificVMK.Name
                IP = $SpecificVMK.IP
                SubnetMask = $SpecificVMK.SubnetMask
                VLANId = $VMKVLanId
            } #$ManagementVMKInfo = [PSCustomObject]@{  
            $CompleteVMKInfo += $VMKInfo
        } #foreach ($VMK in $VMKArray) {
    
        $CompleteVMNetInfo = @()
        $VirtualMachines = $ESXi | Get-VM 
        foreach ($VM in $VirtualMachines) {
            $VMNetAdapters = $VM | Get-NetworkAdapter 

            foreach ($VMNet in $VMNetAdapters) {
                if ($VMNet.ExtensionData.DeviceInfo.Summary -match 'DVSwitch') {
                    $VMNetworks = [PSCustomObject]@{
                        VMName = $VM.Name
                        AdapterName = $VMNet.Name
                        PortGroupName = $VMNet.NetworkName
                        EsxiName = $VM.VMhost
                    } #$VMNetworks = [PSCustomObject]@{
                }  #if ($VMNet.ExtensionData.DeviceInfo.Summary -match 'DVSwitch') {
            $CompleteVMNetInfo += $VMNetworks
            } #foreach ($VMNet in $VMNetAdapters) {
        } #foreach ($vm in $VirtualMachines) {
    
        $MainObj = New-Object psobject
        $MainObj | Add-Member -Name EsxiHost -MemberType NoteProperty -Value $ESXi.Name
        $MainObj | Add-Member -Name ConnectionState -MemberType NoteProperty -Value $ESXi.ConnectionState
        $MainObj | Add-Member -Name PowerState -MemberType NoteProperty -Value $ESXi.PowerState
        $MainObj | Add-Member -Name PhysicalNics -MemberType NoteProperty -Value $PNicInfo
        $MainObj | Add-Member -Name VMKernels -MemberType NoteProperty -Value $CompleteVMKInfo
        $MainObj | Add-Member -Name VMNetwork -MemberType NoteProperty -Value $CompleteVMNetInfo
        $OverAllInfo += $MainObj
    }#foreach ($ESXi in $EsxiHosts) {
} #Process
End {
    $OverAllInfo | ConvertTo-Json | Out-File -FilePath $JsonFile
} #End

In the next article I will use this Json database to migrate between virtual networks.

Useful Articles
VMWARE VCENTER 6.5 UPGRADATION ERROR
PART 2 : CONFIGURING ESXI ON VMWARE WORKSTATION HOME LAB
POWERCLI - CREATE DATACENTER AND ADD ESXI HOST IN VCENTER
PART 1 : BUILDING AND BUYING GUIDE IDEAS FOR VMWARE LAB

How to Install and Use Microsoft PowerShell on Linux

November 30, 2017 01:50PM

As Microsoft has made Powershell open source and can be installed and used on different operating system family (Linux and MacOS), Basically Microsoft is working towards new Powershell Core make it available everywhere now and it is cross platform. As I don't have much knowledge on bash scripting, I can use my PowerShell scripting knowledge on Linux to write some scripts for automation. Powershell core can be downloaded from https://github.com/PowerShell/PowerShell. There are different powershell application packages available on github for different OS flavors.

Github microsoft powershell for linux centos, rpm, deb download, Powershell DSC on linux

Once downloaded PowerShell rpm file I have used WinSCP tool to copy/transfer rpm file on Linux server. When I list directory where RPM file is stored with ls -l, file name shows in Red. Red color means it can not be executed and installed. To make it executable and modify permissions run command chmod +777 powershell-xxx.rpm, once again I run ls -l, file color shows Green and good to execute run. (I don't have yum repository configured so I am using rpm file)

Powershell on centos linux DSC, chmode 777, execute rpm, rpm qa, microsoft powershell core rhel.png

To install package run command - sudo yum install -y powershell-xxx.rpm. This ask for sudo root password, while installation few lines need to read from onscreen installation logs, there are no dependencies for Powershell, and it is installed successfully.  

Powershell rpm yum install on linux, sudo, dependancies resolved, microsoft powershell core, installed successfully

Next I am using putty to login Linux server (Powershell yellow colored commands are not visible correctly on white background terminal). I can view and verify Powershell rpm is installed successfully using rpm -qa powershell command. Type powershell in the console (case sensitive) to execute powershell, but in my case it shows error as bash: powershell: command not found... Instead use pwsh command. and try normal cmdlets (ie: Get-Process, Get-Command) to check it is working as expected.

redhat centos powershell rhel, putty, rpm, linux on powershell dsc, pwsh, get-process linux, get-command linux, desired state configuration.png

Command exit will close powershell and come back to bash shell. I am not master on Linux, but I do normal troubleshooting very well, here I can add alias powershell to pwsh in /etc/profile using command echo 'alias powershell='pwsh'' >> /etc/profile. next time I can execute powershell by running powershell only.

redhat centos powershell rhel, putty, rpm, linux on powershell dsc, pwsh, get-process linux, get-command linux, desired state configuration, get-executionpolicy, echo, alias powershell, source load profile, get-variable

When Powershell is installed on Linux it is located under default path /opt/microsoft /powershell/6.xxxxx/. Next verify powershell version using command $PSVersionTable.

Microsoft powershell core linux psversion psedition, root opt folder, psversiontable install powershell on linux centos

Useful Blogs
Different ways to bypass Powershell execution policy :.ps1 cannot be loaded because running scripts is disabled
Installing, importing and using any module in powershell
POWERSHELL PS REMOTING BETWEEN STANDALONE WORKGROUP COMPUTERS 

Join domain ESXi to an Active Directory OU : Powercli

November 27, 2017 02:44PM

I received request from my internal team to provide a small solution on Esxi Domain join and created when pulled it in domain computer account should be created in specific OU (Organization Unit). To perform this task first, we need complete OU path, to find it open Active Directory Users and Computers, on the View menu click Advanced Features. For more on be

POWERCLI AND VSPHERE WEB CLIENT: JOIN ESXI INTO ACTIVE DIRECTORY DOMAIN CONTROLLER
Resolved: Esxi Join domain failed-Error in Active Directory Operations

active directory domain controller, menu view, Advanced Features, esxi computers joing domain

Next click on the OU where you want to create Esxi Computer Account. Right click on OU and go to properties, You will see an Object tab, (This Object tab is only visible when Advanced features is enabled), Under it find Canonical name of object and copy paste OU path.

vmware vsphere esxi active directory domain controller, usn esxi computer account organazation unit, ou properties canonica name of object, object class tab.png

On the ESXi server when you try ESXi Join Domain under Authentication services. Use the path in Domain. Once esxi is joined to domain successfully, you will see new Esxi host computer account is created in active directory dsa.msc. If you are seeing an issue check my below article.

Resolved: Esxi Join domain failed-Error in Active Directory Operations

esxi join domain, domain settings, organization unit, ou using credentials.vmware vsphere, vcenter, proxy server, active directory users and computers, esxi computer account type


Next Same task I will perform using Active directory Powershell plug in and VMware vSphere Powercli. First to get OU canonical name running below command. Installing, importing and using any module in powershell
Get-ADOrganizationalUnit -Filter {Name -eq 'ESXi'} -Properties Canonicalname | Select CanonicalName

On the vSphere Powercli execute below command, This joins multiple Esxi server to AD domain at once to selected OU.
Get-VMHostAuthentication | Set-VMHostAuthentication -Domain 'vcloud-lab.com/Demo/ESXi' -JoinDomain -Username 'vkunal@vcloud-lab.com' -Password 'Computer@1' -Confirm:$false

POWERCLI INITIALIZE-POWERCLI ENVIRONMENT.PS1 CANNOT BE LOADED BECAUSE RUNNING SCRIPTS IS DISABLED
VMWARE VSPHERE POWERCLI INSTALLATION AND CONFIGURATION STEP BY STEP

Microsoft active directory module, get-AdorgnizationalUnit, ou, canonicalname, Get-vmhostauthentication, set-vmhostauthentication, join domain,domain membership, vmware vsphere, powercli,powershell,domain controller.png

If there are no errors on PowerCLI while executing commands, Computer Accounts are created successfully and same can be verified using below one liner cmdlet.
Get-ADComputer -SearchBase 'OU=ESXi,OU=Demo,DC=vcloud-lab,DC=com' -Filter *

Microsoft active directory module, get-AdorgnizationalUnit, ou, canonicalname, Get-ADComputer, searchbase ou, computer account, join domain,domain membership, vmware vsphere, powercli,powershell,domain controller.png

Useful Blogs
VMWare Powercli: Time Configuration (NTP - Network Time Protocol) on multiple Esxi server
vSphere PowerCLI - Configure syslog on VMware ESXi hosts and Enable security profile firewall

Resolved: Esxi Join domain failed-Error in Active Directory Operations

November 26, 2017 11:07AM

This is some times common, you document something and if don't implement it or use something since long, you might forget knowledge or the issues you resolved earlier. I was automating join domain ESXi servers, while trying joining I was keep getting error: Errors in Active directory operations. I already had written article for the same. POWERCLI AND VSPHERE WEB CLIENT: JOIN ESXI INTO ACTIVE DIRECTORY DOMAIN CONTROLLER, here I have mentioned to check few ports. But everything was working. but still getting below error.

vmware vsphere vCenter esxi, authentication services, join domain, directory services configuration, local authentication, errors in active directory operations, domain credentials

After going through my earlier article, As per above screenshot I was using correct credentials, but wrong way. You must not use DomainName\UserName while providing credentials. Instead you must use it as UserName@DomainName.com, As shown it will be successful immediately.

vmware vsphere esxi vcenter, configure join domain, leave domain, domain settings trusted domain controllers, correct way, errors in active directory operations, trusted Domain controllers, esxi cannot join to domain

Next if you are using Powercli to deploy this task and using user name same way DomainName\UserName in the credentials, It will throw same error. 

cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:

Credential
Set-VMHostAuthentication : 11/25/2017 8:53:36 PM        Set-VMHostAuthentication                The operation for the entity "esxi001.vcloud-lab.com" failed with the following message: "Errors in Active Directory operations."
At line:1 char:59
+ ... d-lab.com | Set-VMHostAuthentication -Domain vcloud-lab.com -Credenti ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-VMHostAuthentication], ActiveDirectoryFault
    + FullyQualifiedErrorId : Client20_TaskServiceImpl_CheckServerSideTaskUpdates_OperationFailed,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostAuthentication

In the second example I used username in email form UserName@DomainName.com in the credential pop up box. and it was successful.

vmware vsphere web client, vCenter, Esxi, Powercli, Get-VMhostAuthentication vmhost, Set-Vmhostauthentication domain credential get-credential, joindomain confirm, Errors in Active directory operations

Useful Blogs
POWERCLI AND VSPHERE WEB CLIENT: JOIN ESXI INTO ACTIVE DIRECTORY DOMAIN CONTROLLER
How to configure DNS on esxi server
VMWARE SECURITY BEST PRACTICES: POWERCLI ENABLE OR DISABLE ESXI SSH
Reset forgotten ESXi root password on Domain joined Esxi using vSphere web client and Powercli

Part 4: Remove ESXi Host from Distributed switch and migrate to virtual switch completely

November 25, 2017 02:44PM

This is last and final part of this article series from migrating distributed switch to standard switch. In this series I have already created and copied existing dvswitch and its portgroup to new standard switch, then migrated Management network and vMotion VMkernel virtual network adapter to standard switch. In the 3rd article I shown critical task of moving virtual machines to another network (Standard switch port groups). After this, only main task left is removing ESXi from distributed switch, and add second physical network adapter to standard switch. This will make switch redundant. With this ESXi server is ready to disconnected, remove from one vCenter server inventory and move/add to another vCenter server.

Earlier Parts
Part 1 - Copy or clone distributed virtual switch portgroups to standard switch portgroups - Powercli
Migrating move back from Distributed virtual switch to Standard virtual switch - VMKernal Adapter - Part 2
Migrating move back from Distributed virtual switch to Standard virtual switch - VMs (Virtual Machine) - Part 3
Part 4: Remove ESXi Host from Distributed switch and migrate to virtual switch completely

To start, In the Vmware vSphere web client, select esxi server, go to configure tab, select Virtual Switches, locate distributed switch, and click on X red button. This will ask and open Remove host from distributed switch message confirmation box, Click yes if you are agree, Press refresh button and only standard switch will be listed.

Note: Before removing esxi host from distributed switch, make sure you have followed earlier posts and there is no dependency like no VMs and VMkernel exist on dvSwitch for the host as shown below, confirm on assigned port groups filter applied, showing: it must be 0.

vmware vsphere web client, esxi, vcenter, remove host from distributed switch, distributed switch to standard switch migration, assigned port groups filter applied, showing

Same task can be perform using another procedure, If you have multiple hosts to remove from dvswitch, this is very step is useful. Go to networking tab, choose distributed switch and right click. In the Add and Manage hosts, Select Remove hosts task to perform on selected distributed switch.

vmware vsphere web client, esxi, vcenter server, dvswitch distributed switch add and manage hosts, remove hosts, standard switch migration, navigator, esxi removal from dvswitch portgroups

In the Select hosts, click Attached Hosts, choose ESXi servers from select member hosts list, click OK to list in another pane in the wizard.

vmware vsphere web client, esxi, vcenter, distributed vswitch add and manage hosts, select member hosts, attached hosts, dvswitch migration, select hosts in distributed switch, standard switch

Once esxi host is attached, click next to go on the final page of ready to complete, review your settings selections before finishing the wizard.

vmware vsphere web client, esxi vcenter, add and manage hosts, dvswitch, distributed switch select hosts, attached hosts, ready to complete review your settings

Now go to the Esxi server >> Configure >> Virtual Switches, select standard switch, click on add and manage physical network adapter to selected virtual switch button. 

vmware vsphere web client, vcenter esxim virtual standard switch add physical nic adapter to vswitch, remove esxi host from distributed switch, switch to switch migration vmkernel and vms

This opened new wizard, On the Manage physical adapters page click + button to Add physical network adapters to switch and make sure add it to Active adapters. These are almost same steps, perform in the second article. Difference is now we are adding 2nd nic.

vmware vsphere esxi vcenter web client, manage physical network adapters for virtual switch, active, standby, unused adapters, cdp lldp, failover old groups, all , properties

Here configuration is complete now and I have completed migration from distributed switch to standard switch without loosing any connectivity, with proper redundancy and No VM outage. (one or two ping loss while migration is expected.)vmware vsphere web client, vcenter esxi, vcloud, virtual switches conifguration, standard swtich, physical network adapters migration

Useful Articles
VMWARE VCENTER 6.5 UPGRADATION ERROR
PART 2 : CONFIGURING ESXI ON VMWARE WORKSTATION HOME LAB
POWERCLI - CREATE DATACENTER AND ADD ESXI HOST IN VCENTER
PART 1 : BUILDING AND BUYING GUIDE IDEAS FOR VMWARE LAB
Copy or clone distributed virtual switch portgroups to standard switch portgroups - Powercli

View older posts »