Combining output powershell into csv and html

techdrive
techdrive used Ask the Experts™
on
I have these three commands here that works well with the output.What I would like to do is combine all three of these in one script and have the out put to come out in a csv and also a html with the following



#First command
get-mailbox -resultsize:unlimited | foreach { ($_.emailaddresses -like "smtp:*").Count -gt 1 -and $_.primarysmtpaddress -match '^[\W]' -or } | Select Displayname, emailaddress, alias

Open in new window


#Second command
get-mailbox | foreach {$_.recipienttypedetails -like "shared*"} | Select Displayname, emailaddress, alias

Open in new window


#Third Command
get-mailbox -resultsize:unlimited | where {$_.displayname -notmatch '^[\W]' } | Select Displayname, emailaddress, alias

Open in new window





Here are the results for the first command
 
      Displayname, emailaddress, alias
      Displayname, emailaddress, alias
      Displayname, emailaddress, alias



      Here are the results for the second command


      Displayname, emailaddress, alias
      Displayname, emailaddress, alias
      Displayname, emailaddress, alias


      Here are the results for the third command

      Displayname, emailaddress, alias
      Displayname, emailaddress, alias
      Displayname, emailaddress, alias
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
$output=@()
$var1 = get-mailbox -resultsize:unlimited | foreach { ($_.emailaddresses -like "smtp:*").Count -gt 1 -and $_.primarysmtpaddress -match '^[\W]' } | Select Displayname, emailaddress, alias
$output += $var1
$var2 = get-mailbox | foreach {$_.recipienttypedetails -like "shared*"} | Select Displayname, emailaddress, alias
$output += $var2
$var3 = get-mailbox -resultsize:unlimited | where {$_.displayname -notmatch '^[\W]' } | Select Displayname, emailaddress, alias
$output += $var3
$output
# $output | format-list
#$output | ConvertTo-Html -Body | Out-File -FilePath c:\test\output.html
#

Open in new window

you can pipe any of the $var?'s or $output to whatever
Quibble: putting everything on one line makes it hard to debug and maintain. It doesn't cost anything to split into separate lines and format accordingly.

The first get-mailbox had a hanging -or after the -match

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial