Need help with how an e-mail outputs a variabel; it doesn't do it correctly.

Welcome Forums General PowerShell Q&A Need help with how an e-mail outputs a variabel; it doesn't do it correctly.

Viewing 3 reply threads
  • Author
    Posts
    • #176572
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Hello,

      I’m in the process of working with a script that will check which users whose account has expired, ie has an expiration date that has passed. It should then deactivate the account and send an e-mail to the responsible manager and tell that now that the account of an employee you are responsible for has been deactivated and a decision needs to be made for what to do with their mailbox and other in Office 365. It is part of our off-boarding process so to speak 🙂

      However, have encountered a problem with the e-mail; the idea is that the manager in charge should get in his mail who / whom it applies, but I can not get that information in the mail. So need help with the part where it is printed in the mailing ticket which one or what employees it is.

      It should add that I work with a script that I am not at all a father to, but have had to take over the work. I understand the logic of how it should work, but I don’t get it with the email formatting.

      In the script, the following line applies which does not do what I want it to do:

      The idea then is that the variable $manEmp should spit out all employees whose account that has been disabled and show for the person receiving the email is responsible for. After much searching and troubleshooting, I can’t figure out what that line should look like to get to it in the way it is intended.

      Here comes the script in its entirety. The line I need help with (everything else is working as it should) is further down just before the “create the email section”:

      I am grateful for all the help I can get with this! Am sorry if it is long and hard to read or if it is the wrong forum to ask in, say so I am looking for further.

    • #177661
      Participant
      Topics: 11
      Replies: 127
      Points: 764
      Helping Hand
      Rank: Major Contributor

      A couple things to suggest:

      1. You can simplify $manEmp to this (no need for double-call of Get-ADUser):
      2. If $manEmp is not empty, you can try this for name output:

        or:

    • #177664
      Participant
      Topics: 11
      Replies: 127
      Points: 764
      Helping Hand
      Rank: Major Contributor

      You may want to consider including the users’ SamAccountName/UserPrincipalName in the email so that managers can identify accounts for offboarding more accurately than just referencing the Name/DisplayName.

    • #177670
      Participant
      Topics: 13
      Replies: 1758
      Points: 3,153
      Helping Hand
      Rank: Community Hero

      Personally, I would gather all of the information with Get-ADuser rather than using Search-ADAccount. Next, rather than send multiple emails to a manager, you may want to consider grouping users which works for 1 or 100 users, but the manager gets a single email. Here is some code to play with:

Viewing 3 reply threads
  • The topic ‘Need help with how an e-mail outputs a variabel; it doesn't do it correctly.’ is closed to new replies.