Get distinguishname of a list of computers

I would like to get distinguishname of the computers in “LAPS-Computers2.txt”. The script keeps running and do not get any output. Please could you assist me to understand and achieve my objective.

$computers = gc .\LAPS-Computers2.txt
foreach ($computer in $computers) {
Get-ADComputer -Filter * | select -Property @{n=“computername”;e={“$_.name”}} | ft name
}

Kiran,
Welcome to the forum. :wave:t3:

What do you have in your input file LAPS-Computers2.txt? And just out of curiousity how many computers do you want to query?

With your code you query ALL COMPUTERS of your AD again and again for each individual element you have in your input file. If there are a lot of elements in your input file you put an enormous stress to your AD with this query.

I you have the computernames in your input file you may use something like this:

$computerList = Get-Content -Path .\LAPS-Computers2.txt
foreach ($computer in $computerList) {
Get-ADComputer -Identity $computer | 
    Select-Object -Property name 
}

And BTW:
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )