Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How to get my script to append the values in the CSV file for a value that is not found?

$
0
0

I have been trying to get a simple script together to import details of various teams from a master file and then user their samaccountname to query AD for further details. However, some of the samaccountnames have changed, and these are just being ignored. I need the script to output an entry to the CSV file it exports to in order that we know that this specific AD user account was not found. I know this is very basic, but after Googling other people's scripts, what I found was not really suitable for cannibalizing code. If someone can direct me on how I can do this, that would be really helpful.

Script as below:

$team='wintel'
$users = import-csv "C:\temp\$team.csv"
$users | ForEach-Object {Get-AdUser -filter "samaccountname -eq '$($_.StandardAccount)'" -properties memberof} `
| Select-Object Name, SamAccountName,UserPrincipalName,@{n='memberOf';e={$_.memberOf -join '; '}} | Export-Csv "C:\temp\Results\Standard\$team.csv"


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>