I am trying to send an email message using powershell. That the body of the email will contain the results of the Get-ADuser command I run that is stored in a variable. When I try the code below I get the error "Send-MailMessage : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Body'. Specified method is not supported."
Is there something wrong with what I am doing here?
$Value = Get-ADUser -Filter * -Properties propery.. | foreach { $_.propery..}
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Value
The -body parameter expects a string to be passed to it. You will need to convert your variable to be type string or manipulate its value to be a string. You can accomplish this in numerous ways.
Send-MailMessage -From $From -To $To -Subject $Subject -Body ($Value | Out-String)
Out-String works here because it takes your object ($Value), which is a single array object containing multiple ADUser objects, and converts it into a single string.
See Out-String for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With