0

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

2 Answers 2

1

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
    }
Sign up to request clarification or add additional context in comments.

Comments

0

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"    
    }

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.