[英]How to find if a list of computers on are a domain using Powershell?
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. 我需要检查IP(或主机名)的列表(.txt),以查找它们是否与域连接,并相应地执行任务。 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. 我尝试修改脚本以适合自己,但是我对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. 您可以将代码与-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
}
If you have a list of valis server names, you could check if they have a corresponding computer account in AD: 如果您有清单服务器名称的列表,则可以检查它们在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"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.