SAM2009
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?
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
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).
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
1- What "?" sign is used for?
2- How in you code I can add: search in this specific OU only
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot!
ASKER
Thanks a lot!