I need to check a list (.txt) of IP's (or hostnames) to find if they are domain connected or not and perform a task accordingly. I found this post here ( How to find if the local computer is in a domain? ) which is almost exactly what I'm after except it does it for the local machine. I tried to modify the script to suit but I don't have much experience with PowerShell.
If anyone is able to help it would be much appreciated. Cheers David
You can use the code with -Computername parameter and provide explicit credentials in case the remote computer administrator credentials are different from what you are using.
$cred = Get-Credential
$servers = Get-Content C:\scripts\Servers.txt
Foreach ($server in $servers) {
if ((gwmi win32_computersystem -computername $server -Credential $cred).partofdomain -eq $true) {
#Do something Here
} else {
#Do something Here
}
If you have a list of valis server names, you could check if they have a corresponding computer account in AD:
Get-Content .\Servers.txt | Foreah-Object {
if(Get-ADComputer -Filter {Name -eq $_})
{
"machine $_ is a part of default domain"
}
else
{
"machine $_ IS NOT a part of default domain"
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.