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

4

2 回答 2

1

您可以使用带有 -Computername 参数的代码并提供显式凭据,以防远程计算机管理员凭据与您使用的凭据不同。

$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
    }
于 2013-06-17T04:19:54.963 回答
0

如果您有 valis 服务器名称列表,您可以检查它们是否在 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"    
    }

}
于 2013-06-17T13:06:04.173 回答