相关疑难解决方法(0)

将PowerShell对象输出到字符串中

此代码启动ping:

$ProcessInfo = New-Object System.Diagnostics.ProcessStartInfo
$ProcessInfo.FileName = "ping.exe"
$ProcessInfo.RedirectStandardError = $true
$ProcessInfo.RedirectStandardOutput = $true
$ProcessInfo.UseShellExecute = $false
$ProcessInfo.Arguments = "localhost"
$Proc = New-Object System.Diagnostics.Process
$Proc.StartInfo = $ProcessInfo
$Proc.Start() | Out-Null
Run Code Online (Sandbox Code Playgroud)

当我在命令中输入$ Proc时,

$Proc
Run Code Online (Sandbox Code Playgroud)

我明白了:

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     27       3     1936       1852    10     0.02   6832 PING
Run Code Online (Sandbox Code Playgroud)

我想将数据行转换为字符串.

所以我尝试了这个:

$Proc | Format-table -HideTableHeaders
Run Code Online (Sandbox Code Playgroud)

我得到了这个:

 27       3     1936       1852    10     0.02   6832 PING
Run Code Online (Sandbox Code Playgroud)

我试过这个:

$Foo = $Proc | Format-table -HideTableHeaders …
Run Code Online (Sandbox Code Playgroud)

string format powershell

9
推荐指数
1
解决办法
3万
查看次数

标签 统计

format ×1

powershell ×1

string ×1