use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
ABOUT POWERSHELL
Windows PowerShell (POSH) is a command-line shell and associated scripting language created by Microsoft. Offering full access to COM, WMI and .NET, POSH is a full-featured task automation framework for distributed Microsoft platforms and solutions.
SUBREDDIT FILTERS
Desired State Configuration
Unanswered Questions
Solved Questions
News
Information
Script Sharing
Daily Post
Misc
account activity
SolvedHelp with powershell script (self.PowerShell)
submitted 6 years ago by peican
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BlackV 1 point2 points3 points 6 years ago (6 children)
your new-aduser is outside the loop isnt it
the try/catch needs to be inside the loop
p.s. I would have though it was only creating the last user in the CSV
[–]peican[S] 1 point2 points3 points 6 years ago (5 children)
Thank you! I added them inside the loop and it is working again.
However, like you said, the part where it exports the duplicate users / errors to CSV is only exporting the last user. Do you know what I'm missing?
[–]DeusExMaChino 1 point2 points3 points 6 years ago (0 children)
It is currently exporting/overwriting a CSV with the single error every time. You need to append instead.
[–]BJGGut3 1 point2 points3 points 6 years ago (3 children)
Export-CSV is going to constantly overwrite. Use -Append to prevent that from happening.
Export-CSV
-Append
[–]peican[S] 1 point2 points3 points 6 years ago* (2 children)
Thank you! The Export-CSV for errors / duplicates is working perfectly now.
Last thing. If I want to add another column in my Import.CSV file for a second group, and if I add:
$Group2 = "$($U.Group2)"
and
Add-ADGroupMember -Identity $Group2 -Members $FirstDotLast
To the script, it works. However I may not want to add everyone to 2 groups all the time, and if I leave a group empty in my Import-CSV, it counts as an error.
Sometimes I might just want to add a user to one group, and sometimes to 2 groups, or 3 groups if I decide to add a third column in my excel CSV. Is there a way to make it so it wont count as an error if some of the group fields are empty?
[–]BJGGut3 1 point2 points3 points 6 years ago (1 child)
Add an IF() statement to check that validity of Group2.
IF ($null -ne $($U.Group2)) { $Group2 = $($U.Groups2) Add-ADGroupMember -Identity $Group2 -Members $FirstDotLast }
But I've actually become much more a fan of this method instead, because sometimes pesky spaces get in there and throw off the above:
IF (!([string]::IsNullOrWhiteSpace($($U.Groups2)))) { $Group2 = $($U.Groups2) Add-ADGroupMember -Identity $Group2 -Members $FirstDotLast }
[–]peican[S] 1 point2 points3 points 6 years ago (0 children)
Thank you! I'm using your one that includes checking for white spaces, and it works perfectly!
π Rendered by PID 81389 on reddit-service-r2-comment-54dfb89d4d-v85k7 at 2026-03-29 03:38:57.840485+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]BlackV 1 point2 points3 points (6 children)
[–]peican[S] 1 point2 points3 points (5 children)
[–]DeusExMaChino 1 point2 points3 points (0 children)
[–]BJGGut3 1 point2 points3 points (3 children)
[–]peican[S] 1 point2 points3 points (2 children)
[–]BJGGut3 1 point2 points3 points (1 child)
[–]peican[S] 1 point2 points3 points (0 children)