Author Posts

July 14, 2017 at 1:29 am

I have a very small script that use to get a reverse info with a list of users in ADPS...


$csv = Import-csv "C:\My Scripts\list.txt"
$error.clear()
foreach($User in $csv)
{
$User = $User.User
$User
Get-QADUser $User | ft name,DisplayName,Email,PrimarySMTPAddress >> reverse_file.csv
}

... the problems come when, the list that some ask me to review doesn't have the exact info. This make that the result file return me a false positive or in case that the username been ambiguous, it return 2 or more similar results.

How I can do to limit the query only to the value that is in the source file, and in case that the username doesn't exist write "something"?

July 14, 2017 at 3:14 am

$csv = Import-csv "C:\My Scripts\list.txt"
$error.clear()
foreach($User in $csv){
$User = $User.User
$User
If ($qad = Get-QADUser $User) {$qad | Select-Object name,DisplayName,
Email,PrimarySMTPAddress | export-csv .\reverse_file.csv} Else {"$user does not exist" | out-file .\no_user_file.txt -append}
}

July 14, 2017 at 10:47 am

If the rest is all the same:

...Select-Object -Unique...

July 14, 2017 at 1:51 pm

If the list has duplicates, you would do something like this:

foreach($User in $csv | Select User -Unique){