I want the ability to pull from AD a list of computers as an array and then import a csv report which also contains computers as an array and compare them. I think my problem is that both arrays don’t have identical columns in them so I’m stripping each temporarily down to just host name to host name to do the comparison.
I’m looking for a new array that contains the computers that are in AD but missing off the list. I want to keep all the attributes that I’ve already pulled (or pull them again I don’t really care) to be able to do… stuff… the action doesn’t really matter for this question against this modified array.
This will get me the host names of what computers I’m missing. How do I get all the other attributes back (Description, location, roomNumber… ect)? If there is a better way to do this completely I’m also open to suggestions.
Instead of saving the property you need to compare in the variable, just reference it where needed. As far as the properties being populated, when I ran the first line as you had it, it would strip out DNSHostname, Distinguishedname, etc. If you want to use select, try as I have it listed with a select *, and then individual properties that are not already present in the propertyset. If you include a property that already exists, you’ll get an error like this
select : The property cannot be processed because the property "name" already exists.
Just as an aside note: To reduce the stress you put on your DC and even to speed up your script you should avoid using the asterisk (*) for the parameter -Properties of the cmdlet Get-ADComputer oder Get-ADUser. Espexcially when you’re already using it for the -Filter parameter.
A good way to make the code a little easier to read would be like this: