Forum Discussion
send powershell script output by email
- Nov 26, 2020
You can do something like this:
$output = @()
$licenses = Get-MsolAccountSku
foreach ($license in $licenses){
$UnusedUnits = $license.ActiveUnits - $license.ConsumedUnits
$output += "$($license.SkuPartNumber) has $unusedUnits unused licenses"
}
Well you are overwriting your $output variable on each iteration. Instead, you should add to it, or use a list, or whichever other method you prefer.
thank you very much for your answer wich i m sorry is not obsvious for me.
i don't see how to add it instead.
i'm trying to keep this script simple without any file insertion.
thanks for your help
- VasilMichevNov 26, 2020MVP
You can do something like this:
$output = @()
$licenses = Get-MsolAccountSku
foreach ($license in $licenses){
$UnusedUnits = $license.ActiveUnits - $license.ConsumedUnits
$output += "$($license.SkuPartNumber) has $unusedUnits unused licenses"
}- eli_sorowNov 26, 2020Copper Contributor
Hi,
the send-mailMessage comand doesn't like the "+" parameter in $output +=
and when i remove it , i have got the same result (only one line)
- VasilMichevNov 26, 2020MVP
You dont need to change that cmdlet, just replace the stuff I posted above.