#$AllVMHosts = Get-Cluster AVAYA*,LINUX*,ODM*,ORACLE*,SQL*,SQL2-DR,TEL*,WAS*,WINDOWS* | Get-VMHost | Sort-object Name

$VMhostNames = @"
itdbisvm-av05.nd.gov
"@

$VMhostNames = ConvertTo-Array -MultiLineString $VMhostNames

$AllVMHosts = Get-VMHost $VMhostNames


$AllVMHosts = Get-Cluster WINDOWS2 | Get-VMHost

ForEach ($VMHost in $AllVMHosts) {
    Clear-DnsClientCache
    $VirtualSwitch = $null
    $CohesityDNS = $null
    $IpAddress = $null
    $VMHostDNS = $VMHost.Name
    $VirtualSwitch = $VMHost | Get-VirtualSwitch -Name "*Data*"
    $PortGroup = $VirtualSwitch | Get-VirtualPortGroup | Where-Object Name -Like "dvPG_3534_10.2.170.0_24*"
    $CohesityDNS = $VMHostDNS.split('.')[0] + 'co.nd.gov'

    # does vmhost already have vmkernel in Cohesity range?
    If ($VMHost | Get-VMHostNetworkAdapter -VMKernel | Where-Object IP -Like "10.2.170.*") {
        Write-Warning "VMKernel already exists on $VMHostDNS"
    }
    Else {
        $IpAddress = (Resolve-DnsName -Name $CohesityDNS).IpAddress
        If ($IpAddress) {
            New-VMHostNetworkAdapter -VMHost $VMHost `
                -PortGroup $PortGroup `
                -VirtualSwitch $VirtualSwitch `
                -IP $IpAddress `
                -SubnetMask 255.255.255.0 `
                -ManagementTrafficEnabled $true `
                -VMotionEnabled $false `
                -VsanTrafficEnabled $false
        }
        else {
            Write-Error "IpAddress null for $VMHostDNS"
        }
    }
}


<# Create DNS records
$AllVMHosts = @"
itdvmbismgmt01.nd.gov
itdvmbismgmt02.nd.gov
itdvmbisvapp01.nd.gov
itdvmbisvapp02.nd.gov
itdvmbiswas04.nd.gov
itdvmbiswas05.nd.gov
itdvmbisora02.nd.gov
itdvmbisora03.nd.gov
itdvmbissql09.nd.gov
itdvmbissql10.nd.gov
itdvmbissql11.nd.gov
itdvmbiswin07.nd.gov
itdvmbiswin08.nd.gov
itdvmbiswin09.nd.gov
itdvmbiswin10.nd.gov
itdvmbiswin11.nd.gov
itdvmbiswin12.nd.gov
itdvmbiswin13.nd.gov
itdvmbissql07.nd.gov
itdvmbissql08.nd.gov 
itdvmmdnmgmt01.nd.gov
itdvmmdnvapp01.nd.gov
itdvmmdnsql07.nd.gov
itdvmmdnsql08.nd.gov
itdvmmdnsql09.nd.gov
itdvmmdnlin05.nd.gov
itdvmmdnora02.nd.gov
itdvmmdnmgmt02.nd.gov
itdvmmdnvapp02.nd.gov
itdvmmdnsql10.nd.gov
itdvmmdnsql11.nd.gov
itdvmmdnsql12.nd.gov
itdvmmdnlin03.nd.gov
itdvmmdnlin04.nd.gov
"@
$AllVMHosts = ConvertTo-Array -MultiLineString $AllVMHosts
#Get-Cluster WINDOWS2,WAS2,SQL2,SQL2-DR,TEL2,PS2,ORACLE2,ODM2,LINUX2,AVAYA2 | Get-VMHost
ForEach($VMHost in $AllVMhosts){
    $CohesityDNS = $VMHost.split('.')[0] + 'co.nd.gov'
    New-ITDIbDNSRecordNextAvailableIP -CIDR 10.2.170.0/24 -Credential $IbCred -Hostname $CohesityDNS
    #$CohesityDNS
}
#>

# static routes
$AllVMHosts = Get-VMHost -Name itdmdnvm-av03.nd.gov
$result = [System.Collections.ArrayList]@()
ForEach ($VMHost in $AllVMHosts) {
    $x = $null
    $esxcli = Get-EsxCli -VMHost $VMHost -V2
    $params = @{
        network = '10.2.169.128/26'
        gateway = '10.2.170.1'
    }

    $esxcli.network.ip.route.ipv4.add.Invoke($params)

    $x = $esxcli.network.ip.route.ipv4.list.Invoke() | Where-Object {$_.Interface -eq 'vmk2' -and $_.Network -eq '10.2.169.128'}
    $x | Add-Member -Name "Name" -MemberType NoteProperty -Value $VMHost.Name
    $null = $result.Add($x)
}