I'm trying to run the below code and get the results to an HTML email. If I just run it as is, all of the output is on one line, which is a mess. I thought I could save the foreach right to an array, but that's not working. . . Just getting a blank array. If I run it without, I get output to the screen, so I know I'm getting results.
Connect-MsolService -Credential $Credential
$customers = Get-MsolPartnerContract -All
$body = @(foreach ($customer in $customers) {
if ($customer.defaultdomainname -notlike "*Domain1*" -and $customer.defaultdomainname -notlike "*DomainABC*") {
Get-MsolUser -All -EnabledFilter EnabledOnly -TenantId $($customer.TenantId) | ? {$_.StrongAuthenticationRequirements.State -eq $null -and $_.isLicensed -eq "TRUE"} | select UserPrincipalName
}
})
foreachoutput like this works. How do you output$body? I guess there's where the error lies.$bodyafterwards? How are you composing the html?