Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 168455

Elseif frustrations

$
0
0

Hi,

 

I have been creating several functions to copy config from a template host, to help set-up the host profiles on new clusters. The current function below is to copy the Authentication information

 

 

$SrcVIHost = "ESXi-1"

$DstVIHost = "ESXi-2"

$vCenterServer = "127.0.0.1"

 

Connect-VIServer -Server $vCenterServer | Out-Null

Function Copy-AdConfig {

    # Check each host and their domain membership status

    $a = Get-VMHost -Name $SrcVIHost | Get-VMHostAuthentication | Select VmHost, Domain, DomainMembershipStatus

    $b = Get-VMHost -Name $DstVIHost | Get-VMHostAuthentication | Select VmHost, Domain, DomainMembershipStatus      

    if (($a.domain -eq $b.domain) -and ($a.domainmembershipstatus -eq $b.domainmembershipstatus)) {

        Write-Host "The Domain Configuration is correct"

        }

    elseif ($b.domain -eq $null) {

        Write-host "No Domain Configured, adding to domain"

        if ($ApplyChanges -eq "Yes") {

            $ADcred = Get-Credential

            Write-Host "Joining domain" $a.domain

            Get-VMHost $DstVIHost | Get-VMHostAuthentication | Set-VMHostAuthentication -Domain $a.domain -User $ADcred.UserName -Password $ADcred.password -JoinDomain

            }

        }

        else {

            Write-host "b Changes Disabled not applying"  -foregroundcolor "Yellow"

            }

    elseif (($a.domain -ne $b.domain) -and ($a.domainmembershipstatus -eq $b.domainmembershipstatus)) {

        Write-host "Different Domains Configured, adding to correct domain"

        if ($ApplyChanges -eq "Yes") {

            $ADcred = Get-Credential

            Write-Host "Leaving domain" $b.domain

            Get-VMHost -Name $DstVIHost  | Get-VMHostAuthentication | Set-VMHostAuthentication -LeaveDomain

            Write-Host "Joining domain" $a.domain

            Get-VMHost $DstVIHost | Get-VMHostAuthentication | Set-VMHostAuthentication -Domain $a.domain -User $ADcred.UserName -Password $ADcred.password -JoinDomain

            }

        }

        Else {Write-host "a Changes Disabled not applying"  -foregroundcolor "Yellow"}

    else {

        Write-Host "Something went wrong with AD Membership"

        }

}

Copy-adConfig

 

Now the issue I am getting is this error on the second elseif

 

The term 'elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


If I swap the the two elseif's around i get the error on the second again. I realise this is more or a powershell issue but someone here will be able to understand what I am doing


Thanks


Viewing all articles
Browse latest Browse all 168455

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>