I have a simple scripts that call a .csv file. The script looks for each line and when it founds in will insert in Active Directory for me (adds user to a group), but when the user # doesn’t exist, it doesn’t add but it won’t continue doing the rest. I get “objectnotfound”.
How do tell it to skip it if it can’t find and add, but continue doing the rest of them? I have a script now, but it stops when it can’t find (errors), but it won’t do the rest that exist.
If it’s a halting error and you really don’t care about the error you can typically add -ErrorAction SilentlyContinue to the command that is halting to have it continue execution or have a try/catch block around the erroring command
Well I assure you I am no mind reader, and speculate the rest of the forum users aren’t either. Your sample shows no header. How can we help with inaccurate information? Also, please edit your code per these instructions.
You acctually don’t need a loop!! Actually a loop bothers more than it helps because you do the same action again and again for each line in your CSV.
You’re using $Snumber.EmployeeID inside your loop while your loop variable is actually $EmployeeID
And BTW: When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.
Please format your code and error messages always as code …
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.