我需要一些帮助。我编写了一个PowerShell脚本,它将文本文件作为输入来获取计算机名称列表。然后,它会检查Active Directory中的计算机名称。如果找到机器,则将其写入一个文本文件,如果找不到该机器,则将其写入单独的文件。我的想法是获得两个名单...... A" good"和一个"坏"名单。问题是它只查询我所在的域,我需要它来查询林中的所有域并且卡住了。谁有人伸出援助之手?这是我的代码:
Import-Module ActiveDirectory
$AdminCredentials = Get-Credential "Domain\AdminAccount"
$objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$domains = @($objForest.Domains | Select-Object Name)
$computers = gc -Path "C:\MachinesInDifferentAds.txt"
$computer_count = $Computers.Length;
$i = 0;
foreach ($computer in $computers) {
Try
{
(Get-ADComputer $computer -Credential $AdminCredentials | FT Name)
$computer | out-file -append -filepath "C:\ComputersInAd.txt"
}
Catch
{
$computer | out-file -append -filepath "C:\ComputersNotInAd.txt"
}
$computer_progress = [int][Math]::Ceiling((($i / $computer_count) * 100))
Write-Progress "Querying the AD" -PercentComplete $computer_progress -Status "Percent Complete - $computer_progress%" -Id 1;
Sleep(1);
$i++;
}