Just getting in PowerShell and seeing if it’s possible to combine Get-ADUser and send-MailMessage commands? What i’m trying to do is find any enabled accounts in an OU then email out the list. I’ve seen examples of putting the results into a file first then sending the email but would’ve thought it can be done form the Get-ADUser output.
I can run the AD lookup script and send-MailMessage separately but can’t seem to get it working within one script.
Sorry, i don’t think i was clear. I don’t want to send an email to any user who’s account is enabled, but to a shared mailbox so we can audit the accounts.
It should work, the issue being body needs to be a string and not an object (I had to go back and redo my initial answer). However, I would think export-csv and then attaching it would make the list more manageable if you have a lot of accounts to sift through
Yeah, I let that out. I tend to do something like “subject = Blah from $env:computername” So I know what server generates the email, in case years later there’s a question on how its being generated.