Who is Participating?

Here, I've simplified two of the options. The information displayed by the "Edited AD User" block is always up-to-date, that's the reason for setting the $AD_User.<whatever property> to the input. I never saw a case where it was displaying the original information with the previous code, but I wasn't looking for that specifically, so I suppose it's possible I missed it. With these two I'm always seeing the updated information.

How about something like this? The choice is set up as a function, one of the choices moves on to the next user, one of the choices exits the script, for the rest you would put in the code to make the change. The function is continually looped through until you've parsed through all the users or have chosen to exit.

@Subsun: Yes, it is working. I appreciate your help. But, as you know when you are sort of developing, you work by stages with lots of validation and conditionals. While you keep progressing you find out little things to improve or what do with the code.

Querying Employee from file against Active Directory+++ FOUND THE FOLLOWING EMPLOYEE IN FILE +++++++LASTNAME: RoseroFIRST NAME: GermanDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID: 1111CLOCK NUMBER: 2222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++============= FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY =========LASTNAME: RoseroFIRST NAME: GermanDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID:CLOCK NUMBER: 2770=======================================================================NOTE: Is this the right Employee, You are working on? (Y/N): yNOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the File? (Y/N): nWhich of the following Employee information would you like to change in Active Directory ?1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER. 8 = Move on to NEXT USER. 0 = EXIT: 1Type the new LAST Name:: RoseAre you sure, you want to replace the following Lastname "Rosero" by "Rose" (Y/N): yNew LastName SET############ I AM STUCK, RIGHT HERE. What if i typed the wrong last name ?# I can ask, "Do you need to change anything else on this user ?" If Yes. I should come #back to the choices statement and of course $AD_USER continues to be Rose, do the #change, will prompt Do you need to change anything else on this user ?, if No, will move #to the next user on the file and AD#########Querying Employee from file against Active Directory+++++++ FOUND THE FOLLOWING EMPLOYEE IN FILE ++++++++++++++++LASTNAME: SilveiraFIRST NAME: RodrigoDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID: 1111CLOCK NUMBER: 2222++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++============ FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY ========LASTNAME: SilveiraFIRST NAME: RodrigoDEPARTMENT: Information ServicesTITLE: Sr System/Network AdministratorTELEPHONE NUMBER: 333-333-3333FLEX ID: 3333CLOCK NUMBER: 2222========================================================================NOTE: Is this the right Employee, You are working on? (Y/N):

As your code stands right now, you don't need the While loop (and its $i variable). I thought it may be of some use based on some earlier scrap that I had seen, but right now it's just extra fluff.

I think you're going to want to restructure some of your elements. Most likely after each edit you will want to query the info from AD again for the specific user to show its current values. I'm not sure whether you would want to also re-show the info from the list.

I would put this in at about line 67 or possibly 77

[bool]$sameuser = $true$iteration = 0While ($sameuser){ #Include this If statement if the info has already been shown before the While loop If ($iteration -ne 0) { "show_current_info" } If ($iteration -eq 0) { $iteration++ $RightWrong = Read-Host 'NOTE: Is this the right Employee, You are working on? (Y/N)' Write-Host "" if ($RightWrong -eq "N") { Write-Host "Moving to the next user" [void]$foreach.moveNext() } } #Assume that any response other than "N" means it is the correct user, could use an Else but it's pretty much implied edit_AD_User}

A choice of "next user" (maybe should be called "None") in response to the question "what information do you want to edit?" would exit the loop and move on, instead of having separate questions for "is the information correct?", but you could put the following right before the edit_AD_User function call if you want.

In response to your question about typing a wrong last name, etc., I would question why you are entering anything. Why not just use the information obtained from the file, isn't that what it's for? But in any case, this loop will keep asking you if you want to change anything, so any screwups can be redone.

0

namergSystems AdministratorAuthor Commented: 2013-01-08

@footech, i am taking your suggestion from the beginning and is helping me but always get stuck in certain things (I posted a new question)

Do you think if I do a flow chart diagram will give you a better idea of what I am looking for?

My code works with your flowchart, though I still think after each edit you will want to fetch and display the info for the current user before asking if you want to edit again. Here it is inserted into the sample you provided (there are a couple comments inline):

A couple issues:
- I left out a closing "}" before the Else on line 47.
- I don't think the [void]$foreach.moveNext() will skip the rest of the code in the loop. Might be better to put a break statement here.

0

namergSystems AdministratorAuthor Commented: 2013-01-09

Thank footech, but I am still stuck....

This is the result...

Querying Employee from file file against Active Directory+++++ FOUND THE FOLLOWING EMPLOYEE IN file FILE ++++++++++++++++++++++++++LASTNAME: RoseroFIRST NAME: GermanDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID: 1111CLOCK NUMBER: 2222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++============================ FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY ==========================LASTNAME: RoseroFIRST NAME: GermanDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID:CLOCK NUMBER: 2770==========================================================================================================NOTE: Is this the right Employee, You are working on? (Y/N): yNOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the file File? (Y/N): nWhich of the following Employee information would you like to change in Active Directory ?1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER. 8 = Move on to NEXT USER. 0 = EXIT: 1Type the new LAST Name:: RoseAre you sure, you want to replace the following LASTNAME "Rosero" for "Rose" (Y/N): yRose, GermanNew LastName SET#LETS SAY I TYPED THE WRONG LAST NAMEDo you still want to correct anything else on this user? (Y/N): yWhich of the following Employee information would you like to change in Active Directory ?1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER. 8 = Move on to NEXT USER. 0 = EXIT: 1Type the new LAST Name:: Rosero#HERE IS THE PROBLEM, IT SHOULD DISPLAY "Rose" for "Rosero"Are you sure, you want to replace the following LASTNAME "Rosero" for "Rosero" (Y/N):

You're referring to line 49? That's because you're still using $($AD_User.sn) to display the lastname. After any change is made to user info, potentially any reference to an object in $ad could be incorrect because $ad was created/populated before the change. Nothing in the edit function is making a new query for updated information.

One way you might handle this to make the query for AD users (the $ad variable), use it to match against the list like you currently do, but then once the match has been verified and you're inside the loop, perform another query for the specific AD user info and store it to a new variable ($current_user), then use this new variable anytime you need to get or set attributes. Each time through the While loop the variable would be updated.

More so line 31 (i.e. the first time you're changing it). Assuming the info in the file is correct (which is the whole reason you're checking AD against it isn't it), then just update the AD info with info from the file, then you don't have to worry about mistyping anything, and will be simpler and quicker.

0

namergSystems AdministratorAuthor Commented: 2013-01-09

@footech got it.

But, I think the FOR gets stuck in a loop. This is the result, Line 49

Querying Employee from file file against Active Directory+++++ FOUND THE FOLLOWING EMPLOYEE IN file FILE ++++++++++++++++++++++++++LASTNAME: RoseroFIRST NAME: GermanDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID: 1111CLOCK NUMBER: 2222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++======== FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY ================LASTNAME: RoseroFIRST NAME: GermanDEPARTMENT: Information ServicesTITLE: Sr System/NetworkAdministratorTELEPHONE NUMBER: 303-333-3333FLEX ID: 1111CLOCK NUMBER: 2222========================================================================NOTE: Is this the right Employee, You are working on? (Y/N): yNOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the file File? (Y/N): nWhich of the following Employee information would you like to change in Active Directory ?1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = FLEX ID. 7 = CLOCK NUMBER. 8 = Move on to NEXT USER. 0 = EXIT: 7Type the new CLOCK Number:: 2770Are you sure, you want to replace the following CLOCK number "2222" for "2770" (Y/N): yNew Clock Number SETDo you still want to correct anything else on this user? (Y/N): yWhich of the following Employee information would you like to change in Active Directory ?1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = FLEX ID. 7 = CLOCK NUMBER. 8 = Move on to NEXT USER. 0 = EXIT: 7Type the new CLOCK Number:: 4444Are you sure, you want to replace the following CLOCK number "2770" for "4444" (Y/N): yNew Clock Number SETDo you still want to correct anything else on this user? (Y/N): n#RIGHT HERE, WHEN ALL CHANGES ARE DONE FOR A XYZ USER IN AD, @FILE_USER NEEDS TO READ THE NEXT USER AND AD_USER START QUERIES AGAINST AD, CLEAR SCREES AND START ALL OVER WITH THE WRITE HOST. WE ARE ALMOST DONE.End of Edit_AD_User function

Sorry.. I was busy the whole day.. didn't get much time to check your flow chart.. I have quickly done following code which I think will loop as you required. It will prompt to change until you press 0 to exit for a user.. Check and let us know if this is what you are looking for.

PS: I didn't add many check points, just concetrated on the loop.. If it is fine with you then you can add the confirmation questions later..

From my last code post, I needed to move line 3 to around 34 so that the $sameuser variable is reset in the foreach before beginning the While loop. We could also change the While loop to a Do-Until so that it runs through at least once.

@namerg - I don't know where the following came from.
"Do you still want to correct anything else on this user? (Y/N): " - as seen on line 47 of your last output. The code I posted is looping through the users fine in my testing.

If you want the screen to clear between each user, you'll have to add a Clear-Host command inside the ForEach loop.

Sorry for all the posts.
Just thought I'd mention I spotted an error in the logic of the script. You're trying to match the last name of users found in AD against the last name in a file. If the AD info is wrong (or the list info), you'll never get a match. So not much point in having an option to change the last name. You'll probably want some logging commands around where Subsun has "Else {"No user Found in AD for $($User.SN)"}", so that you can manually check any users that don't get a match.

0

namergSystems AdministratorAuthor Commented: 2013-01-09

@footech. The file is going to be 100% correct. AD not. Hmm, maybe you missed "Do you still want to correct anything else on this user? (Y/N):"

@Subsun: You code worked for the repetitive menu. Although, I do still have issues moving to the next user. It should be something like:

User_File pulled first record from CSV and looks for matching last name in AD. If the lastname is unique no problem. But, if the last name IS NOT unique,(more than one user with a lastname Dean) User_File should keep first record in memory and User_AD should move to the next possible non-unique last name. That is why the question in my previous versions of the code. See below question and result.

"$RightWrong = Read-Host 'NOTE: Is this the right Employee, You are working on? (Y/N)'"

Can you point me to a code sample where you have "Do you still want to correct anything else on this user? (Y/N): " - I'm not seeing it anywhere.

Even if the file is 100% correct, if the last name in AD is wrong you won't get a match. So my point stands.

My code is working and Subsun's should too. I would suggest that you re-examine any code modifications you've made or your sample data that you're testing with to check for blocking issues.

0

namergSystems AdministratorAuthor Commented: 2013-01-10

@footech: Lastnames in AD are 100% correct

@Subsun.
Check this out. I am working with your code and adjusted to my needs.
So, file read the first record from csv file, found a match in AD. Perfect, it prompted to change any information, Perfect. But, Ok. I am done with this user. So, I chose "0" it should move to the next user/record on File.CSV and displays it, then again look for that user in AD.

Guys, I am willing to go straight all night long on this project this coming Friday night. If you guys are willing to help me. I do appreciate it.

You can choose the code which you can understand and best suits to you... We both can help... Honestly I cannot assure you time (I guess no one can) as I have a full time job and a Jr.Subsun to take care, but sure will jump in whenever I am free.. :-)

For this question If I press Y the you don't want to edit the user right?

0

namergSystems AdministratorAuthor Commented: 2013-01-10

Correct. if information from User-File is correct with User-AD, (Y) is chosen and File should move to the next record and Queries AD one more time to find a possible match according with last name from the user on File.

But, if user on file matches lastname with aduser but everything else is different, aduser should jump to the next record until finds the right user.

#Chose (0)
#Problem, it does not display Dean, Patrick on AD.
This is how the script works..When it go to edit mode it will loop in attribute changes until you press 0.. Once you press 0 it will finish edit and move to next CSV user. Else it will b confusing..

IMO You probably want to reface the question..NOTE: Do you want to Edit this AD user? (Y/N): or something like that.. Press Y to Edit and N to move to next user.. Does it make sense?

I think for it to work the way you're expecting, from your last code post, remove the break from line 274, and keep the break after the Clear-Host around line 308 as mentioned in comment #a38764695.

Other option is to rework the question and choices a bit. See the following (you may notice that I changed all the Write-Host commands to Write-Output, doesn't really change what you will see with the functionality of the script at this point, but makes viewing a transcript much easier):

I don't think I see a point in making what was in place into separate functions. If you just want separate questions for: 1) confirming the user; and, 2) confirming (or not) the user information is correct, before being presented with any edit options - then you can add that to the code we were just working with. What you just posted appears to go back to what we had in comment #a38763820

0

namergSystems AdministratorAuthor Commented: 2013-01-11

@Footech,

The think is the ForEach loop are sequential and they will never go back at least for the AD part. So, I had make it a function.

Did you copy all the code I posted and just modify it for your environment or did you pull out the bits I changed and paste it back into your code? If the latter, I think something was missed. I think you would get the results above if you didn't label the Foreach loop so the Break doesn't work as intended.

In my testing, everytime I press 8 it advances to the next user in the CSV. The one thing I hadn't verified was the following scenario:
If there are 2 users with the last name "Smith" in the CSV, but only 1 in AD, pressing 0 after the first (incorrect) match is found advances to the next user in the CSV without showing a notification that no further match was found in AD.

...which isn't the same as what I posted. The break in the function has to reference a label to break out of the proper loop (which has to have the same label).

Here's the code again, copy it in it's entirety and just edit the parts necessary for your environment or use a file comparison utility to help you spot all the differences between what you posted. FYI, I have also included some additional code to handle the scenario I mentioned in my previous post.

Scenario 1: Reads CSV and AD and finds a perfect match and if all info is good, choose 8, CSV jumps to next record and AD queries for the next possible match. PERFECT

Scenario 2: CSV jumps to next record and AD queries for the next possible match and if incorrect math, 0 is pressed and finds the right match. PERFECT

Scenario 3. Reads CSV and AD and finds a perfect match and NOT all info is good, and info gets corrected on AD, PERFECT

This one is not working:
Scenario 4: Reads CSV, AD and finds a perfect match and if NOT all info is good, info gets corrected on AD but ONCE all info is corrected CSV needs to jumps to next CSV user and AD query stars again.

I'm not sure what the difference between scenarios 3 and 4 is. Do you mean that once scenario 3 is complete you're having trouble getting to the next user?

I haven't looked at all the code you have for making corrections, but I'm thinking you'll always end at the prompt for what info you want to change, whether you've made corrections or not, pressing 8 will advance to the next user in the CSV.

0

namergSystems AdministratorAuthor Commented: 2013-01-11

Ay dios mio...yes sorry...I am getting overwhelmed.

Never mind...I think it is working :) Sorry sorry

0

namergSystems AdministratorAuthor Commented: 2013-01-11

PERFECTO
Love You, love youuuu @footech. You da man.. and Subsun too.

Experts-Exchange should put emoticons like chocolates, kisses, aces or something like that to cheer you.

I will do a full test tomorrow.

I am exhausted. I do have another question which I am going to post in a bit.

I would take out the question "Do you still want to correct anything else on this user? (Y/N):" It's redundant. If you don't want to edit any further information, a response of "None - the info is correct" takes you to the next user.

Simplify a choice like number 2 and make it like the following (apply the same concept to the other choices as well):