使 PowerShell 输出中的换行符在 HTML 中显示
Make line breaks in PowerShell output appear as such in HTML
运行 Invoke-command {net localgroup administrators} -comp computername
并在 HTML 中得到结果。
我如何得到这个带有中断的输出,所以它看起来像直接执行的结果,是这样的:
Alias name administrators
Comment Administrators have complete and unrestricted access to the computer/domain
Members
-------------------------------------------------------------------------------
Domain1\Group1
Administrator
Domain2\Ggroup1
Domain2\Group2
The command completed successfully.
当我将上面的文本放入 HTML 文档中时,我得到如下内容:
Alias name administrators Comment Administrators have complete and unrestricted access to the computer/domain Members ------------------------------------------------------------------------------- Domain\Group1 Administrator Domain2\Group1 Domain2\Group2 The command completed successfully.
即使使用 -replace
和 `n
等,我也只能打破第一行和最后一行,但结果(实际的 domain\group 名称,作为一行) .
您从 Invoke-Command 获得的输出是一个字符串数组。您可以做的最简单的事情是使用 <br />
标签加入输出。
$output = Invoke-command {net localgroup administrators} -ComputerName ...
$output -join "<br />"
运行 Invoke-command {net localgroup administrators} -comp computername
并在 HTML 中得到结果。
我如何得到这个带有中断的输出,所以它看起来像直接执行的结果,是这样的:
Alias name administrators
Comment Administrators have complete and unrestricted access to the computer/domain
Members
-------------------------------------------------------------------------------
Domain1\Group1
Administrator
Domain2\Ggroup1
Domain2\Group2
The command completed successfully.
当我将上面的文本放入 HTML 文档中时,我得到如下内容:
Alias name administrators Comment Administrators have complete and unrestricted access to the computer/domain Members ------------------------------------------------------------------------------- Domain\Group1 Administrator Domain2\Group1 Domain2\Group2 The command completed successfully.
即使使用 -replace
和 `n
等,我也只能打破第一行和最后一行,但结果(实际的 domain\group 名称,作为一行) .
您从 Invoke-Command 获得的输出是一个字符串数组。您可以做的最简单的事情是使用 <br />
标签加入输出。
$output = Invoke-command {net localgroup administrators} -ComputerName ...
$output -join "<br />"