Link to home
Start Free TrialLog in
Avatar of csehz
csehzFlag for Hungary

asked on

PowerShell - Move errors to file

Dear Experts,

I have been running this command to remove users from a certain Active Directory group, basically their names are listed in a .csv file column and from there imported, then for each the command executed and putting the errors to a .txt file:

Import-Csv C:\users\z.cseh\desktop\displaynames.csv | ForEach {remove-adgroupmember -Identi
ty "Users" -Member $_.displayname -Confirm:$false} 2>> c:\users\z.cseh\desktop\DisplayNamesErr.txt


In general that works fine, but relating the errors the issue is that it puts to the .txt file when error happens, but not showing at which .csv line or at which users. Always just repeating this pattern:

User generated image
Could you please advise how to parameterise somehow to show at least at which .csv line the error happened?

Thanks,
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csehz

ASKER

That is great like that the error message and also the users appeared in the file, thanks very much