Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to filter a get-adcomputer command using a text/csv file and output to a CSV

$
0
0

OK, so I'm in the process of trying to get a Windows 7 refresh completed for a large client... I had the bright idea to use AD to find what computers are listed as XP, and determine our progress using that.  Well, I run get-adcomputer, and it returns the results... a whole lot of results that really aren't active anymore.  I obtained a list of systems that have been disposed of, holding for disposal, etc... now my problem is I can't quite figure out how to get that list to be used to exclude those computers from the results... I execute my script, it runs, but it seems to get stuck in a loop... I'm sure I'm missing something VERY basic, but I can't figure it out.  This is the first time I've ever attempted to use the get-content commandlet, so again, I'm sure I'm doing something stupid. 

Any help will be greatly appreciated!

import-module ActiveDirectory
$exclude = get-content c:\scripts\excludes.csv
ForEach ($entry in $Exclude)
{
    $Excl = "*$entry*"
    get-adcomputer -filter {Name -notlike $excl}  | select Name,operatingsystem
} Export-CSV c:\scripts\xpfil.csv


Viewing all articles
Browse latest Browse all 21975

Trending Articles