Garry Shape
asked on
Formatting Powershell ConvertTo-HTML output with linebreaks?
Someone helped make a script for me here but I kind of have a twist on it I'm trying to accomplish
What this code here does is import a list of usernames to run Exchange commands against (Get their Alias,ForwardingAddress, then another nested command that gets mailbox permissions (people who have permissions against that mailbox).
Problem is now I'm trying to convert it out to HTML.
When I do that, the "Permissions" column just kind of puts everything clumped together in its row's table data.
So attempting to add back into the code, replacing
But not in the rendered HTML viewing the actual webpage
I tried doing -join "<BR>" but that just literally displays the <BR> tag in the rendered HTML, it doesn't force a line break.
What this code here does is import a list of usernames to run Exchange commands against (Get their Alias,ForwardingAddress, then another nested command that gets mailbox permissions (people who have permissions against that mailbox).
$path = "H:\mailboxexports.txt"
@(Get-Content $path) | ForEach `
{
$name = $_
Get-Mailbox -identity $name | select Alias,ForwardingAddress, @{n="Permissions";e={(Get-MailboxPermission -identity $name | Select -expand User)}}
} | ConvertTo-HTML | Out-File H:\Mailboxes.htm
Problem is now I'm trying to convert it out to HTML.
When I do that, the "Permissions" column just kind of puts everything clumped together in its row's table data.
So attempting to add back into the code, replacing
@{n="Permissions";e={(Get-MailboxPermission -identity $name | Select -expand User)}}
with@{n="Permissions";e={(Get-MailboxPermission -identity $name | Select -expand User -join "`r`n)}}
The html file output still shows clumped together, however, if I view the source of the webpage, I can indeed see the carriage returns in the source code in the Permissions column.But not in the rendered HTML viewing the actual webpage
I tried doing -join "<BR>" but that just literally displays the <BR> tag in the rendered HTML, it doesn't force a line break.
ASKER
Here's what I've got
So far working with console output then wil try to HTML
But in the console output it adds "@{" before each thing and encloses with a }
And it also lists every item in the list from the text file before proceeding to run the script. not sure how to eliminate those
$UserList = "H:\mailboxexports.txt"
$MasterList = (Get-Content $UserList)
foreach ($User in $MasterList) {
$MyObject = New-Object PSObject -Property @{
EmailAddress = (Get-Mailbox $User).Alias
ForwardingAddress = (Get-Mailbox $User | select ForwardingAddress)
Permissions = (Get-MailboxPermission -identity $User | select User)
}
$MasterList += $MyObject
}
$MasterList
So far working with console output then wil try to HTML
But in the console output it adds "@{" before each thing and encloses with a }
And it also lists every item in the list from the text file before proceeding to run the script. not sure how to eliminate those
That's because it's a multi-valued result (the @{...)
How did you want the output displayed? I can modifiy it for how you want the html to render.
How did you want the output displayed? I can modifiy it for how you want the html to render.
You could also try just joining with a space between each:
Permissions = (Get-MailboxPermission -identity $User | select -ExpandProperty User) -join " "
}
Permissions = (Get-MailboxPermission -identity $User | select -ExpandProperty User) -join " "
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@footech
Holy crap how did you do that
Holy crap how did you do that
:)
A lot of what I've learned about PowerShell has been from researching questions that others have posed here.
A lot of what I've learned about PowerShell has been from researching questions that others have posed here.
So the issue is layout.
You can have repeated Aliases with each permission:
Alias1 Perm1
Alias1 Perm2
Alias1 Perm3
etc. Or, you can generate a table with some rowspanning:
Alias1 Perm1
Perm2
Perm3
Which should produce better output... But I'm not clear on what you're wanting for output. Can you elaborate?