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
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
}
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
}
Thanks pkolom i tried your script but i didnt get any output file may be at the moment when i run the script i do not have any host out of domain.
Thanks for your timely help, i will keep running this and check it can resolve my issue.
Glad it helped
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
}