This Cmdlet show object tree HtmlView by using LINQPad HTML Writer.
This Cmdlet use LINQPad.exe http://www.linqpad.net/
Get-WinEvent Application -MaxEvents 10 | Out-HtmlView
Get-Command Get-Help | Out-HtmlView -Depth 10
This Cmdlet show object tree HtmlView by using LINQPad HTML Writer.
This Cmdlet use LINQPad.exe http://www.linqpad.net/
Get-WinEvent Application -MaxEvents 10 | Out-HtmlView
Get-Command Get-Help | Out-HtmlView -Depth 10
#TODO:support for non serializable object(example:PSCustomObject) | |
function Out-HtmlView | |
{ | |
[CmdletBinding()] | |
param( | |
[Parameter()] | |
[int]$Depth = 2, | |
[Parameter(Mandatory,ValueFromPipeLine)] | |
$InputObject | |
) | |
begin | |
{ | |
$ErrorActionPreference = "Stop" | |
#Load LinqPad assembly | |
$exePath = Join-Path ${env:ProgramFiles(x86)} "LINQPad4\LINQPad.exe" -Resolve | |
[Reflection.Assembly]::LoadFile($exePath) > $null | |
#Load WPF assembly for Powershell.exe | |
Add-Type -AssemblyName PresentationFramework | |
#Create LINQPad HTML Writer | |
$writer = [LINQPad.Util]::CreateXhtmlWriter($false) | |
#Create WPF Window object | |
$xaml = @" | |
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> | |
<Grid> | |
<WebBrowser x:Name="Browser"/> | |
</Grid> | |
</Window> | |
"@ | |
$window = [Windows.Markup.XamlReader]::Parse($xaml) | |
$window.Topmost = $True | |
$browser = $Window.FindName("Browser") | |
} | |
process | |
{ | |
#Need to use foreach to support -InputObject parameter | |
foreach($item in $InputObject) | |
{ | |
#if(($item -is [PSObject]) -and ($item.PSObject.BaseObject -ne $null)) | |
#{ | |
# $item = $item.PSObject.BaseObject #Unwrap object | |
#} | |
$writer.WriteDepth($item,$Depth) | |
} | |
} | |
end | |
{ | |
try{ | |
#Write-Host ("FormattingTime: {0} [ms]" -f $writer.FormattingTime.TotalMilliSeconds) | |
$html = $writer.ToString() | |
$writer.Dispose() | |
$browser.NavigateToString($html) | |
#Use Dispatcher.InvokeAsync to avoid problem<https://gist.github.com/altrive/6227237> | |
$async = $window.Dispatcher.InvokeAsync({ | |
$window.ShowDialog() | Out-Null | |
}) | |
$async.Wait() | Out-Null | |
} | |
catch{ | |
Write-Error $_.Exception | |
} | |
finally{ | |
if($browser -ne $null){ | |
$browser.Dispose() | |
} | |
if($window -ne $null){ | |
$window.Close() | |
} | |
} | |
} | |
} |