Link to home
Start Free TrialLog in
Avatar of SAM2009
SAM2009Flag for Canada

asked on

How to send PowerShell result by email?

Hi,

I would like to send by email these 2 PowerShell results:

Get-User -resultsize unlimited | where {$_.WhenCreated -gt (get-date).adddays(-7)} | ft Name,whenCreated -Autosize
Get-Mailbox -resultsize unlimited | Where-Object {$_.WhenMailboxCreated –ge ((Get-Date).Adddays(-7))} | ft name

How can I do that?
Avatar of Joseph Moody
Joseph Moody
Flag of United States of America image

Send-Mailmessage is the cmdlet that you'll use. You can export those results to a csv and then use the attachment parameter to add them to your email.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM2009

ASKER

What this mean?: $body = @()
This sets up an empty array.
That array is then used to build the text lines -  one array element per line.
For using it in the email body, we need to "glue" the lines together into a single string with proper line breaks (`r`n = carriage return, line feed).
Avatar of SAM2009

ASKER

Thanks. I have 2 questions:

1- What "?" sign is used for?

2- How in you code I can add: search in this specific OU only
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SAM2009

ASKER

Thanks a lot!
Avatar of SAM2009

ASKER

Thanks a lot!