• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

How to jump to the next an Active Directory User within a ForEach statement ?

Hello,

I have a foreach statement that queries/reads AD users and prompts some questions while querying the AD. If there is a question that answers No, it will have to jump to the next user.

code:
$ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=ou,DC=domain,DC=com" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber

foreach ($AD_User in $ad) {
      if ($file[0].sn -eq $AD_User.sn)
      {
            #Write-Host "BINGO FOUND IT"
               #Ask Questions
              $RightWrong = Read-Host 'NOTE: Is this the right Employee, You are working on? (Y/N)'

#I AM STUCK HERE...
if $RightWrong -eq "N" {

     #It needs to jump to the next AD user and Ask questions
}
}

Thanks for your help,
0
namerg
Asked:
namerg
  • 18
  • 14
2 Solutions
 
SubsunCommented:
Try..
if ($RightWrong -eq "N") {break}

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
Hey Guru Subsun,

But will it not break the "for" statement ?
0
 
SubsunCommented:
Yes it will.. If you are looking to go to next value in loop itself then try..
if ($RightWrong -eq "N") {$foreach.moveNext() | Out-Null}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
namergSystems AdministratorAuthor Commented:
hmm, it did not move to the next AD user, it kept the same value or AD User found on the if statement.  
if ($file[0].sn -eq $AD_User.sn) {....}
0
 
namergSystems AdministratorAuthor Commented:
By the way this is all related to my previous questions, it is like a mini application but with poweshell.
0
 
SubsunCommented:
I think you have to place the second IF statement outside the first one.. Try this..
foreach ($AD_User in $ad) {
      if ($file[0].sn -eq $AD_User.sn)
      {
      #Write-Host "BINGO FOUND IT"
      #Ask Questions
      $RightWrong = Read-Host 'NOTE: Is this the right Employee, You are working on? (Y/N)'
      }
      if ($RightWrong -eq "N") {[void]$foreach.moveNext()}
}

Open in new window

0
 
namergSystems AdministratorAuthor Commented:
Same thing,

Result:
======== FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY ========
LASTNAME: Silveira
FIRST NAME: Rodrigo
DEPARTMENT: Information Services
TITLE: Sr System/NetworkAdministrator
TELEPHONE NUMBER: 303-333-3333
EMPLOYEE ID:
EMPLOYEE NUMBER:
=================================================

NOTE: Is this the right Employee, You are working on? (Y/N): n

#The following comes after the following code:
#if ($RightWrong -eq "N") {
#                  #break
#                  [void]$foreach.moveNext()
#                  Write-Host "LASTNAME: $($AD_USER.sn)"
#                  Write-Host "FIRST NAME: $($AD_USER.givenName)"
                  
            }
#Same user as == FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY ======== section

LASTNAME: Silveira
FIRST NAME: Rodrigo

NOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the File? (Y/N): PS C:\scripts\AD>
0
 
SubsunCommented:
BTB there will be only one user which match condition $file[0].sn -eq $AD_User.sn right? It yes.. Ideally the script should exit if you input "N". Please correct me if I am wrong in my assumption..
0
 
namergSystems AdministratorAuthor Commented:
Correct. The result of that of IF is, 1, True.
But think about that can be more than one User with a lastname Silveira.
0
 
SubsunCommented:
[void]$foreach.moveNext()
                 Write-Host "LASTNAME: $($AD_USER.sn)"
                  Write-Host "FIRST NAME: $($AD_USER.givenName)"

Write-Host here will not write the next user, if will just write the same user which is in pipeline..

It would be better if you can post the complete code..
0
 
namergSystems AdministratorAuthor Commented:
Here it goes:

*******************************************************

Clear-Host
$file  = Import-Csv "c:\scripts\ad\temp\file.csv" -header sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
$ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=OU,DC=colo,DC=pvt" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
Write-Host "Querying   Employee from   file against Active Directory"
Write-Host ""
Write-Host "++ FOUND THE FOLLOWING EMPLOYEE IN   FILE +++++"
#Write-Host ""
Write-Host "LASTNAME: $($ [0].sn)"
Write-Host "FIRST NAME: $($ [0].givenName)"
Write-Host "DEPARTMENT: $($ [0].department)"
Write-Host "TITLE: $($ [0].title)"
Write-Host "TELEPHONE NUMBER: $($ [0].telephoneNumber)"
Write-Host "FLEX ID: $($ [0].employeeID)"
Write-Host "CLOCK NUMBER: $($ [0].employeeNumber)"
#Write-Host ""
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
#Write-Host "Waiting for 5 seconds"
Start-Sleep -Seconds 5
foreach ($AD_User in $ad) {
      if ($file[0].sn -eq $AD_User.sn)
      {
            #Write-Host "BINGO FOUND IT"
            $Flag LastName = 1
            Write-Host ""
            Write-Host "==== FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY =="
            Write-Host "LASTNAME: $($AD_USER.sn)"
            Write-Host "FIRST NAME: $($AD_USER.givenName)"
            Write-Host "DEPARTMENT: $($AD_USER.department)"
            Write-Host "TITLE: $($AD_USER.title)"
            Write-Host "TELEPHONE NUMBER: $($AD_USER.telephoneNumber)"
            Write-Host "EMPLOYEE ID: $($AD_USER.employeeID)"
            Write-Host "EMPLOYEE NUMBER: $($AD_USER.employeeNumber)"
            Write-Host "================================================================"
            Write-Host ""
            $RightWrong = Read-Host 'NOTE: Is this the right   Employee, You are working on? (Y/N)'
            Write-Host ""
            if ($RightWrong -eq "N") {
            #I AM STUCK HERE
                  #break
                  [void]$foreach.moveNext()
                  Write-Host "LASTNAME: $($AD_USER.sn)"
                  Write-Host "FIRST NAME: $($AD_USER.givenName)"
                  
            }
            $YesNo = Read-Host 'NOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the   File? (Y/N)'
            Write-Host ""
            #Write-Host "YesNo Value: $($YesNo)"
            if (($RightWrong -eq "Y") -and ($YesNo -eq "N"))
               {
                        Write-Host "Which of the following Employee information would you like to change in Active Directory ?"
                        Write-Host ""
                        $AD_User_Change = Read-Host '1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER'
                  }
            switch ($AD_User_Change) {
             1 {
                  Write-Host "1"
                  $InputLastName = Read-Host 'Type the new Last Name:'
                  Write-Host ""
                  $NewLastName = Read-Host "Are you sure, you want to replace the following lastname ""$($AD_User.sn)"" by ""$InputLastName"" (Y/N)"
                  if (($NewLastName -eq "y"))
                     {
                        Get-ADUser $AD_User.sAMAccountName  | Set-ADUser -surname $InputLastName -DisplayName $($InputLastName+", "+$AD_USER.givenName) -ErrorAction SilentlyContinue -ErrorVariable Err1
                        Start-Sleep -Seconds 5
                        $NewName = $InputLastName+", "+$AD_USER.givenName
                        Get-ADUser $AD_User.sAMAccountName  | Rename-ADObject -newname $NewName
                        Start-Sleep -Seconds 5
                        Write-Host "New LastName SET"
                        Start-Sleep -Seconds 30
                    }
              }
             2 {Write-Host "2"}
             3 {Write-Host "3"}
             4 {Write-Host "4"}
             5 {Write-Host "5"}
             6 {Write-Host "6"}
             7 {Write-Host "7"}
            }
            Start-Sleep -Seconds 30
      }

}
0
 
SubsunCommented:
Can you try this and see if it gives expected result?
Clear-Host
$file  = Import-Csv "c:\scripts\ad\temp\file.csv" -header sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
$ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=OU,DC=colo,DC=pvt" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
Write-Host "Querying   Employee from   file against Active Directory"
Write-Host ""
Write-Host "++ FOUND THE FOLLOWING EMPLOYEE IN   FILE +++++"
#Write-Host ""
Write-Host "LASTNAME: $($ [0].sn)"
Write-Host "FIRST NAME: $($ [0].givenName)"
Write-Host "DEPARTMENT: $($ [0].department)"
Write-Host "TITLE: $($ [0].title)"
Write-Host "TELEPHONE NUMBER: $($ [0].telephoneNumber)"
Write-Host "FLEX ID: $($ [0].employeeID)"
Write-Host "CLOCK NUMBER: $($ [0].employeeNumber)"
#Write-Host ""
Write-Host "++++++++++++++++++++++++++++++++++++++++++++++++++++++"
#Write-Host "Waiting for 5 seconds"
Start-Sleep -Seconds 5
foreach ($AD_User in $ad) {
      if ($file[0].sn -eq $AD_User.sn)
      {
            #Write-Host "BINGO FOUND IT"
            $FlagLastName = 1
            Write-Host ""
            Write-Host "==== FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY =="
            Write-Host "LASTNAME: $($AD_USER.sn)"
            Write-Host "FIRST NAME: $($AD_USER.givenName)"
            Write-Host "DEPARTMENT: $($AD_USER.department)"
            Write-Host "TITLE: $($AD_USER.title)"
            Write-Host "TELEPHONE NUMBER: $($AD_USER.telephoneNumber)"
            Write-Host "EMPLOYEE ID: $($AD_USER.employeeID)"
            Write-Host "EMPLOYEE NUMBER: $($AD_USER.employeeNumber)"
            Write-Host "================================================================"
            Write-Host ""
            $RightWrong = Read-Host 'NOTE: Is this the right   Employee, You are working on? (Y/N)'
            Write-Host ""
	    }
           If ($RightWrong -eq "N") {
                  [void]$foreach.moveNext()
             }
            
	   If ($RightWrong -eq "Y"){
												
	   $YesNo = Read-Host 'NOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the   File? (Y/N)'
           Write-Host ""
         #Write-Host "YesNo Value: $($YesNo)"
            
	  If ($YesNo -eq "N")
               {
               Write-Host "Which of the following Employee information would you like to change in Active Directory ?"
               Write-Host ""
               $AD_User_Change = Read-Host '1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER'
                }
            switch ($AD_User_Change) {
             1 {
                  Write-Host "1"
                  $InputLastName = Read-Host 'Type the new Last Name:'
                  Write-Host ""
                  $NewLastName = Read-Host "Are you sure, you want to replace the following lastname ""$($AD_User.sn)"" by ""$InputLastName"" (Y/N)"
                  if (($NewLastName -eq "y"))
                     {
                        Get-ADUser $AD_User.sAMAccountName  | Set-ADUser -surname $InputLastName -DisplayName $($InputLastName+", "+$AD_USER.givenName) -ErrorAction SilentlyContinue -ErrorVariable Err1
                        Start-Sleep -Seconds 5
                        $NewName = $InputLastName+", "+$AD_USER.givenName
                        Get-ADUser $AD_User.sAMAccountName  | Rename-ADObject -newname $NewName
                        Start-Sleep -Seconds 5
                        Write-Host "New LastName SET"
                        Start-Sleep -Seconds 30
                    }
              }
             2 {Write-Host "2"}
             3 {Write-Host "3"}
             4 {Write-Host "4"}
             5 {Write-Host "5"}
             6 {Write-Host "6"}
             7 {Write-Host "7"}
            }
            Start-Sleep -Seconds 30
      }

} 

Open in new window

0
 
SubsunCommented:
Add $file[0].sn -eq $AD_User.sn in third If statement..

If ($RightWrong -eq "Y" -and $file[0].sn -eq $AD_User.sn)
0
 
namergSystems AdministratorAuthor Commented:
Hmm, I have to change little bit the logic,

      Elseif ($RightWrong -eq "N")
                        {
                        [void]$foreach.moveNext()
                        Write-Host "Moving to the next user"
                        Start-Sleep -Seconds 30
                        }
                  else
                        {
                        Write-Host "USER DOES NOT EXIST"
                        }
      } #Closes if ($file[0].sn -eq $AD_User.sn)
}closes For statement

But I get the following error:

Elseif : The term 'Elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
that the path is correct and try again.
At C:\scripts\AD\test.ps1:90 char:4
+             Elseif ($RightWrong -eq "N")
+             ~~~~~~
    + CategoryInfo          : ObjectNotFound: (Elseif:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


                [void]$foreach.moveNext()
                Write-Host "Moving to the next user"
                Start-Sleep -Seconds 30

else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
the path is correct and try again.
At C:\scripts\AD\test.ps1:96 char:4
+             else
+             ~~~~
    + CategoryInfo          : ObjectNotFound: (else:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


                Write-Host "USER DOES NOT EXIST"
0
 
namergSystems AdministratorAuthor Commented:
I think is a bug on PowerShell v3..hmmm....
0
 
SubsunCommented:
Elseif ($RightWrong -eq "N")
                        {
                        [void]$foreach.moveNext()
                        Write-Host "Moving to the next user"
                        Start-Sleep -Seconds 30
                        }
                  else
                        {
                        Write-Host "USER DOES NOT EXIST"
                        }

Elseif here doesn’t make any sense to me..

You can try something like..
$adsearch = $ad | Where {$file[0].sn -eq $_.sn}
If ($adsearch -eq $null)
{Write-Host "USER DOES NOT EXIST"}
Else{"Start your script"}

Open in new window


Did you get any error for the code which I suggested? or is it not working as expected?
0
 
SubsunCommented:
And regarding PS 3.0 if bug, If I am not wrong It only fails if the closing curly brace comes in same line with if keyword..
0
 
namergSystems AdministratorAuthor Commented:
Hi Subsun I just got to the office, let me try.
0
 
namergSystems AdministratorAuthor Commented:
Subsun, I get the following error:

Elseif : The term 'Elseif' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, veri
that the path is correct and try again.

At C:\scripts\AD\test.ps1:88 char:4
+             Elseif ($RightWrong -eq "N")
+             ~~~~~~
    + CategoryInfo          : ObjectNotFound: (Elseif:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
                Write-Host "Moving to the next user"
                #[void]$foreach.moveNext()
                #Write-Host "Moving to the next user"
                #Start-Sleep -Seconds 30
else : The term 'else' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify t
the path is correct and try again.
At C:\scripts\AD\test.ps1:95 char:4
+             else
+             ~~~~
    + CategoryInfo          : ObjectNotFound: (else:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


                Write-Host "USER DOES NOT EXIST"

Code:

$YesNo = Read-Host 'NOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the File? (Y/N)'
            Write-Host ""
            #Write-Host "YesNo Value: $($YesNo)"
            #if (($RightWrong -eq "Y") -and ($YesNo -eq "N"))
            if ($RightWrong -eq "Y")
             {
                        Write-Host "Which of the following Employee information would you like to change in Active Directory ?"
                        Write-Host ""
                        $AD_User_Change = Read-Host '1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER'
                  
                  switch ($AD_User_Change)
                  {
                        1 {
                              Write-Host "1"
                              $InputLastName = Read-Host 'Type the new Last Name:'
                              Write-Host ""
                              $NewLastName = Read-Host "Are you sure, you want to replace the following lastname ""$($AD_User.sn)"" by ""$InputLastName"" (Y/N)"
                              if (($NewLastName -eq "y"))
                              {
                                    Get-ADUser $AD_User.sAMAccountName  | Set-ADUser -surname $InputLastName -DisplayName $($InputLastName+", "+$AD_USER.givenName) -ErrorAction SilentlyContinue -ErrorVariable Err1
                                    Start-Sleep -Seconds 5
                                    $NewName = $InputLastName+", "+$AD_USER.givenName
                                    Get-ADUser $AD_User.sAMAccountName  | Rename-ADObject -newname $NewName
                                    Start-Sleep -Seconds 5
                                    Write-Host "New LastName SET"
                                    Start-Sleep -Seconds 30
                              }
                        }

                  }
             }
             Start-Sleep -Seconds 30      
             Elseif ($RightWrong -eq "N")
                      {
                        Write-Host "Moving to the next user"
                        #[void]$foreach.moveNext()
                        #Write-Host "Moving to the next user"
                        #Start-Sleep -Seconds 30
                        }
             else
                        {
                        Write-Host "USER DOES NOT EXIST"
                        }
0
 
SubsunCommented:
Can you try starting Curly Brace in same line with IF statement?
Elseif ($RightWrong -eq "N") {
0
 
namergSystems AdministratorAuthor Commented:
:( same thing.
0
 
namergSystems AdministratorAuthor Commented:
I think I am going to give up for this part using powershell. :( I will do this first part of the project in C# then the second part in powershell.
0
 
SubsunCommented:
I will check in PS 3.0 and let you know..
0
 
namergSystems AdministratorAuthor Commented:
ok thanks a lot.
0
 
namergSystems AdministratorAuthor Commented:
Subsun,

Should I use powershell v2 ?
0
 
SubsunCommented:
I Actually tried Elseif in PS 3.0 and it's working for me.. I will take a close look at your code as soon as I get some time..:-)
0
 
namergSystems AdministratorAuthor Commented:
hmm ok... I will paste the code one more time.
0
 
SubsunCommented:
it's fine, i can take it from old post..
0
 
namergSystems AdministratorAuthor Commented:
Here it goes:

****************************************

Clear-Host
$FILE = Import-Csv "c:\scripts\ad\temp\FILE.csv" -header sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
$ad = Get-ADUser -filter * -Properties sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber  -SearchBase "OU=COMPANY,DC=COMPANYcolo,DC=pvt" | Select-Object  sAMAccountName,sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber
Write-Host "Querying COMPANY Employee from FILE file against Active Directory"
Write-Host ""
Write-Host "++ FOUND THE FOLLOWING EMPLOYEE IN FILE FILE +++++++++++++++"
#Write-Host ""
Write-Host "LASTNAME: $($FILE[0].sn)"
Write-Host "FIRST NAME: $($FILE[0].givenName)"
Write-Host "DEPARTMENT: $($FILE[0].department)"
Write-Host "TITLE: $($FILE[0].title)"
Write-Host "TELEPHONE NUMBER: $($FILE[0].telephoneNumber)"
Write-Host "FLEX ID: $($FILE[0].employeeID)"
Write-Host "CLOCK NUMBER: $($FILE[0].employeeNumber)"
#Write-Host ""
Write-Host"+++++++++++++++++++++++++++++++++++++++++"
#Write-Host "Waiting for 5 seconds"
Start-Sleep -Seconds 5
foreach ($AD_User in $ad) {
      if ($FILE[0].sn -eq $AD_User.sn)
      {
            #Write-Host "BINGO FOUND IT"
            $FlagFILELastName = 1
            Write-Host ""
            Write-Host "==== FOUND THE FOLLOWING EMPLOYEE IN ACTIVE DIRECTORY =="
            #Write-Host ""
            Write-Host "LASTNAME: $($AD_USER.sn)"
            Write-Host "FIRST NAME: $($AD_USER.givenName)"
            Write-Host "DEPARTMENT: $($AD_USER.department)"
            Write-Host "TITLE: $($AD_USER.title)"
            Write-Host "TELEPHONE NUMBER: $($AD_USER.telephoneNumber)"
            Write-Host "EMPLOYEE ID: $($AD_USER.employeeID)"
            Write-Host "EMPLOYEE NUMBER: $($AD_USER.employeeNumber)"
            #Write-Host ""
            Write-Host "==============================================================="
            Write-Host ""
            #$RightWrong = Read-Host 'NOTE: Is this the right COMPANY Employee, You are working on? (Y/N)'
            Write-Host ""
            #Write-Host "RightWrong Value: $($RightWrong)"
            $YesNo = Read-Host 'NOTE: Is the EMPLOYEE Information FOUND In ACTIVE DIRECTORY CORRECT AGAINST The EMPLOYEE Information FOUND In the FILE File? (Y/N)'
            Write-Host ""
            #Write-Host "YesNo Value: $($YesNo)"
            #if (($RightWrong -eq "Y") -and ($YesNo -eq "N"))
            if ($RightWrong -eq "Y") {
                        Write-Host "Which of the following Employee information would you like to change in Active Directory ?"
                        Write-Host ""
                        $AD_User_Change = Read-Host '1 = LASTNAME. 2 = FIRST NAME. 3 = DEPARTMENT. 4 = TITLE. 5 = TELEPHONE NUMBER. 6 = EMPLOYEE ID. 7 = EMPLOYEE NUMBER'
                  
                  switch ($AD_User_Change)
                  {
                        1 {
                              Write-Host "1"
                              $InputLastName = Read-Host 'Type the new Last Name:'
                              Write-Host ""
                              $NewLastName = Read-Host "Are you sure, you want to replace the following lastname ""$($AD_User.sn)"" by ""$InputLastName"" (Y/N)"
                              if (($NewLastName -eq "y"))
                              {
                                    Get-ADUser $AD_User.sAMAccountName  | Set-ADUser -surname $InputLastName -DisplayName $($InputLastName+", "+$AD_USER.givenName) -ErrorAction SilentlyContinue -ErrorVariable Err1
                                    Start-Sleep -Seconds 5
                                    $NewName = $InputLastName+", "+$AD_USER.givenName
                                    Get-ADUser $AD_User.sAMAccountName  | Rename-ADObject -newname $NewName
                                    Start-Sleep -Seconds 5
                                    Write-Host "New LastName SET"
                                    Start-Sleep -Seconds 30
                              }
                        }
                        2 {Write-Host "2"}
                        3 {Write-Host "3"}
                        4 {Write-Host "4"}
                        5 {Write-Host "5"}
                        6 {Write-Host "6"}
                        7 {Write-Host "7"}
                  }
             }
             Start-Sleep -Seconds 30      
             Elseif ($RightWrong -eq "N")
                      {
                        Write-Host "Moving to the next user"
                        #[void]$foreach.moveNext()
                        #Write-Host "Moving to the next user"
                        #Start-Sleep -Seconds 30
                        }
             else
                        {
                        Write-Host "USER DOES NOT EXIST"
                        }
      }
}
*********************************************************************
0
 
SubsunCommented:
Ok Remove Start-Sleep -Seconds 30 it breaks the if statement flow..
0
 
namergSystems AdministratorAuthor Commented:
^&%$# it worked... PERFECT

But I will try something else. I have a meeting in 5 min and I will get back to you.
0
 
namergSystems AdministratorAuthor Commented:
Subsun, you are my hero :)
I need to implement it for the other user properties as you saw in the code. If i get stuck more question on the way.

Thanks for your help, G
0

Featured Post

Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

  • 18
  • 14
Tackle projects and never again get stuck behind a technical roadblock.
Join Now