I’m using Get-Adcomputer to pull computers from AD that have 133 in the name. The command works but I need to put each computer’s name into a variable so that I can use it to get information from each computer.
You’ve got several things wrong. Your WMI calls are getting the local computer information, not the remote computer, so they have to be inside your loop. Next you are referencing $ComputerName, which is an array of objects versus $Name being the current object in your loop. Start with this basic example:
What you are attempting to do is a very common Powershell task. I would recommend getting a book on Powershell or minimally looking at other examples. The example above does not have any error handling if a computer is offline, but as I was saying this a very common task so examples should be easy to find.
Objects are by default “unsorted” and “unordered”. If you like to maintain a special order you will have to sort it when you output it or you can create it already ordered: