例えば、PowerShellのdirコマンドの出力をConvertTo-HTMLで加工してHTAウィンドウに表示します。
htaファイルでは、
<script defer>
document.open();
document.write(new ActiveXObject('wscript.shell').exec('cmd /c <nul powershell "dir|convertto-html -property Mode,Name,Length,LastWriteTime,Attributes|write-host"').stdout.readall());
document.close();
</script>
または、
<script defer>
new ActiveXObject('wscript.shell').run('powershell -Sta "Add-Type -AssemblyName System.Windows.Forms;[Windows.Forms.Clipboard]::SetText((dir|convertto-html -property Mode,Name,Length,LastWriteTime,Attributes|out-string))"',0,true);
document.open();
document.write(clipboardData.getData("text"));
document.close();
</script>
前者はコンソールウィンドウが一時的に開きます。後者はクリップボードを利用します。
コマンドプロンプトやバッチファイルでは、
powershell "dir|convertto-html -property Mode,Name,Length,LastWriteTime,Attributes|write-host"|mshta.exe "about:<script defer>document.write(new ActiveXObject('scripting.filesystemobject').getstandardstream(0).readall());</script>"
パイプが同期で待ち合わせするので、待ち合わせないで非同期にするには、
powershell ~~~|start /b mshta.exe ~~~
印刷は、右クリック、印刷。
保存は、右クリック、ソースの表示、名前を付けて保存。