Get-ADUser - no code runs after that stage RRS feed

  • Question

  • Hi All.

    I am writing a script to send an email to a user.

    I have the user login Id but I am going onto AD to get the users email address, my script does a few things and then gets the users email from AD before attempting to send them an email.

    What I am noticing is that within my code, any line of code after the lines before fails to execute.

    import-module ActiveDirectory

    $details = Get-ADUser -identity $owner -Properties * | Select Name, GiveNname, SamAccountName, EmailAddress $email_address = $details.EmailAddress $name = $details.GiveNname

    Anything before the 4 lines runs fine, I can print out debug messages etc, but after these 4 lines, nothing runs.

    Am I missing something here.

    Thursday, November 21, 2019 12:07 AM

All replies

  • I see only three lines.

    I would rebuild the file as it sounds like it is corupted.


    Thursday, November 21, 2019 12:15 AM
  • I see only three lines.

    I would rebuild the file as it sounds like it is corupted.


    Its not corrupt, there is something happening which means after the Get-AD details runs, even a white-host "test" doesnt print anything out.

    Thursday, November 21, 2019 12:32 AM
  • There is no where near enough information to understand what could cause your issue. Posting the code that doesn't run is no help.


    Thursday, November 21, 2019 12:37 AM
  • Comment out those three lines of code and insert these:

    $u = Get-ADUser -identity  $owner -Properties *
    $email_address = $u.EmailAddress
    $name = $u.GivenName

    Open the script in the ISE or VS Code and place a breakpoint on the 1st line. Verify that the value in  "$owner" is correct. If it isn't, figure out why. If it is, single-step (if you can) to the next line. Did it work? If so, the Get-ADUser worked. If you can't get past the Get-ADUser then try adding "-Verbose" to the cmdlet and try running the script again. If you get any output from the cmdlet maybe it'll point out where the problem lies.

    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)

    Thursday, November 21, 2019 3:23 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Monday, November 25, 2019 9:04 AM