Advertisement

05.29.2008 at 12:44PM PDT, ID: 23442711
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

Error Trap for Object Exists in Powershell

Asked by apsutechteam in Miscellaneous Programming

Tags:

I am attempting to read input from a csv file and add new users.  The basics of this is working.  I am trying to add a trap in case the object exists to log which user object existed, and then iterate to the 'next' of the For loop - to get the next one -- without completing the loop and causing many addtional errors for the user which couldn't be added.  I'm not sure I understand about how/where to put the trap -- I assume at the top of the ForEach -- and I can't figure how to add the code to jump to the next execution of the loop.  I can use a 'continue' within the loop (outside the trap code) to do this -- but I can't figure how to add to the trap code.  Also, why can I not just use the $_.'AccountName' variable in the Trap -- I had to add to a 2nd variable to get this to print out. I eventually will figure out how to write error info to a log -- but now am just working on the basics.
Thanks in advance for any advice.
C EmmonsStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
import-csv "c:\psscripts\test.csv" | ForEach-Object {
 
$current = $_.'AccountName'
 
 
trap [System.DirectoryServices.DirectoryServicesCOMException]
{write-host $current;'exists';$_;
continue
 
}
 
 
 
$usersOU= [ADSI] "LDAP://ou=psstudents, dc=student,dc=apsu,dc=edu"
 
 
$newUser = $usersOU.create("user","cn=" + $_.'AccountName') 
$newUser.SetInfo()
 
 
# Set Account AttributesAMAccountName 
 
$newUser.sAMAccountName = $_.'AccountName'
$newUser.givenName = $_.'FirstName'
$newUser.middlename =$_.'MiddleName'
$newUser.initials=$_.'initial'
$newUser.employeeID = $_.'StudentID'
$newUser.sn = $_.'LastName'
$newUser.UserPrincipalName =$_.'AccountName' + "@apmail.apsu.edu"
$newUser.mail = $_.'AccountName' + "@apsu.edu"
$newUser.displayName = $_.'FirstName' + " " + $_.'Initial' + " " + $_.'LastName'
$newUser.SetInfo()
 
 
 
#$NewUser.SetPassword($_.'StudentID'.ToString())
 
## Set User to Enabled & Set Default Password
 
 
 
$newUser.SetPassword("TopSecret99")
$newUser.userAccountControl="66048"
 
 
$newUser.SetInfo()
 
 
}
[+][-]05.29.2008 at 03:07PM PDT, ID: 21673743

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 08:15AM PDT, ID: 21678547

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 08:26AM PDT, ID: 21678653

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 12:27PM PDT, ID: 21680710

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 01:49PM PDT, ID: 21681323

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 02:47PM PDT, ID: 21681657

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.30.2008 at 07:34PM PDT, ID: 21682481

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 07:57AM PDT, ID: 21692560

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2008 at 08:22AM PDT, ID: 21692803

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Miscellaneous Programming
Tags: Powershell
Sign Up Now!
Solution Provided By: BSonPosh
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628