ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell: Use PS to email results

    IT Discussion
    ps powershell o365 sendmail
    9
    14
    1.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • NerdyDadN
      NerdyDad
      last edited by

      Here is some of my script. Its just a 2 liner, but gets the job done by looking at AD and everybody who hasn't logged in in the last 3 weeks (or whatever set period of time you want to establish based on days:hours:minutes:seconds), puts it into a spreadsheet, stores it in a file server to hold it until the next line. The next line creates the email, and attaches it the csv it just created and sends it along.

      Search-ADAccount -AccountInactive -TimeSpan 20.00:00:00 -UsersOnly -SearchBase "CN=Users,DC=Domain,DC=com" | Select-Object Name,Enabled,LastLogonDate | sort enabled | export-csv \\server\filelocation.csv
      Send-MailMessage -From [email protected] -To [email protected],[email protected] -Subject "Inactive Users" -SmtpServer tennant-com.mail.protection.outlook.com -Attachments \\server\filelocation.csv
      

      Hope that helps.

      ObsolesceO 1 Reply Last reply Reply Quote 1
      • gjacobseG
        gjacobse
        last edited by

        In this case we have the following variables:

        $domain
        $defaultPassword
        $firstname
        $lastname
        $alias
        $teamgroup1
        $teamgroup2


        What I would like to end up with:

        to: person
        cc: person1, person2
        Subject:
        Body:
        $firstname $last name has new email of $firstname + $lastname @ $domain
        Alias of $alias + $domain
        Password: $Defaultpassword
        Group: teamgroup1

        -Regards

        1 Reply Last reply Reply Quote 0
        • ObsolesceO
          Obsolesce @NerdyDad
          last edited by

          @nerdydad said in Powershell: Use PS to email results:

          Hope that helps.

          Really? I thought your reply was meant not to help.

          1 Reply Last reply Reply Quote 1
          • NerdyDadN
            NerdyDad
            last edited by

            @gjacobse

            https://mangolassi.it/topic/13325/creating-a-new-user-with-o365-with-powershell

            gjacobseG 1 Reply Last reply Reply Quote 1
            • gjacobseG
              gjacobse @NerdyDad
              last edited by

              @nerdydad said in Powershell: Use PS to email results:

              @gjacobse

              https://mangolassi.it/topic/13325/creating-a-new-user-with-o365-with-powershell

              Thanks - I'll have to see about working through that and seeing what I can merge into the script I have.

              1 Reply Last reply Reply Quote 1
              • JaredBuschJ
                JaredBusch
                last edited by JaredBusch

                I use a PS script I found on 🌶 to email users when passwords are expiring.

                I would link to it but not allowed.

                Minion QueenM coliverC NerdyDadN 3 Replies Last reply Reply Quote 1
                • Minion QueenM
                  Minion Queen Banned @JaredBusch
                  last edited by Minion Queen

                  @jaredbusch said in Powershell: Use PS to email results:

                  I use a PS script I found on 🌶 to email users when passwords are expiring.

                  I would link to it but not allowed.

                  Sorry that this is such a PITA!! But not my doing.

                  1 Reply Last reply Reply Quote 0
                  • coliverC
                    coliver @JaredBusch
                    last edited by coliver

                    @jaredbusch said in Powershell: Use PS to email results:

                    I use a PS script I found on 🌶 to email users when passwords are expiring.

                    I would link to it but not allowed.

                    I have one from somewhere else let me see if I can find it. Here it is: https://www.serveradventures.com/the-adventures/send-pwdnotification-powershell-script-to-notify-users-of-password-expiration

                    1 Reply Last reply Reply Quote 1
                    • NerdyDadN
                      NerdyDad @JaredBusch
                      last edited by NerdyDad

                      @jaredbusch said in Powershell: Use PS to email results:

                      I use a PS script I found on 🌶 to email users when passwords are expiring.

                      I would link to it but not allowed.

                      Why don't you just copy and paste the script over here?

                      Its your knowledge. Who's to say that YOU can't share it in both places?

                      Sorry. Saw that important word there "found". I rest my case.

                      ObsolesceO 1 Reply Last reply Reply Quote 0
                      • ObsolesceO
                        Obsolesce @NerdyDad
                        last edited by

                        @nerdydad said in Powershell: Use PS to email results:

                        @jaredbusch said in Powershell: Use PS to email results:

                        I use a PS script I found on 🌶 to email users when passwords are expiring.

                        I would link to it but not allowed.

                        Why don't you just copy and paste the script over here?

                        Its your knowledge. Who's to say that YOU can't share it in both places?

                        Sorry. Saw that important word there "found". I rest my case.

                        I find a lot of 🌶 stuff on pastebin.com. No issues with sharing pastebin stuff on ML.

                        scottalanmillerS 1 Reply Last reply Reply Quote 0
                        • scottalanmillerS
                          scottalanmiller @Obsolesce
                          last edited by

                          @tim_g said in Powershell: Use PS to email results:

                          @nerdydad said in Powershell: Use PS to email results:

                          @jaredbusch said in Powershell: Use PS to email results:

                          I use a PS script I found on 🌶 to email users when passwords are expiring.

                          I would link to it but not allowed.

                          Why don't you just copy and paste the script over here?

                          Its your knowledge. Who's to say that YOU can't share it in both places?

                          Sorry. Saw that important word there "found". I rest my case.

                          I find a lot of 🌶 stuff on pastebin.com. No issues with sharing pastebin stuff on ML.

                          Interesting.

                          1 Reply Last reply Reply Quote 0
                          • nadnerBN
                            nadnerB
                            last edited by

                            I can't remember where is nabbed it from, but I use the following:

                            Function Mailer
                                {
                                 $emailTo = ""
                                 $emailFrom = "" 
                                 $subject="It's broken, damn it" 
                                 $smtpserver="" 
                                 $smtp=new-object System.Net.Mail.SmtpClient($smtpServer)
                                 $Message = @" 
                                                             
                                Insert a useful/meaningful message here. 
                            "@ 
                                
                                }
                            
                            
                                 
                            Mailer
                            

                            Last line calls the function (duh for you, but a visitor here might not know).

                            1 Reply Last reply Reply Quote 0
                            • 1 / 1
                            • First post
                              Last post