VMware Cloud Community
RajuVCP
Hot Shot
Hot Shot
Jump to solution

Script to check how many host are out of domain and add it back to domain

    Hi All,

Am facing strange issue as some or few of my esxi host is going out domain and it will be difficult to login and run other regular acitivity.

is there a script which can check overall how many esxi host are out of domain and another script which can add it back to domain.

Thanks a ton in advance

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
1 Solution

Accepted Solutions
pkolom
Enthusiast
Enthusiast
Jump to solution

Hi.

This small script will check all of your hosts for domain name, if none it will put host name to out.txt file in current folder:

$hostnet = Get-VMHost |Get-VMHostNetwork

   $hostnet |foreach{

   if (!$_.DomainName)

    {

    $_.HostName|out-file .\out.txt

    }

   }

Second script takes output generated by first one and adds domain name of your choice to host. It will ask for confirmation.

$nodomainhost = Get-Content .\out.txt

$domain = "your.domain"

$nodomainhost|foreach {

Set-VMHostNetwork -HostName $_ -DomainName "$domain" -Confirm:$true

}

View solution in original post

0 Kudos
3 Replies
pkolom
Enthusiast
Enthusiast
Jump to solution

Hi.

This small script will check all of your hosts for domain name, if none it will put host name to out.txt file in current folder:

$hostnet = Get-VMHost |Get-VMHostNetwork

   $hostnet |foreach{

   if (!$_.DomainName)

    {

    $_.HostName|out-file .\out.txt

    }

   }

Second script takes output generated by first one and adds domain name of your choice to host. It will ask for confirmation.

$nodomainhost = Get-Content .\out.txt

$domain = "your.domain"

$nodomainhost|foreach {

Set-VMHostNetwork -HostName $_ -DomainName "$domain" -Confirm:$true

}

0 Kudos
RajuVCP
Hot Shot
Hot Shot
Jump to solution

Thanks

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
0 Kudos
pkolom
Enthusiast
Enthusiast
Jump to solution

Glad it helped Smiley Happy

You can remove "|out-file .\out.txt" part and then you'll get output on screen or just add one line and get output on screen and in file:

   $_.HostName

   $_.HostName|out-file .\out.txt 

}

0 Kudos