string - Powershell如何将函数输出存储在字符串中?

标签 string powershell powershell-2.0 store

我只是写了一个小脚本,显示了我选择的最新事件日志。

现在,我想将输出存储在字符串中,但是我没有做到这一点。

这是我的功能:

function geteventlog
{

get-eventlog -logname System -EntryType Error -newest 2 |  Select-Object message,source | fl *

}

Powershell 2.0

最佳答案

存储函数输出很简单:

$result = geteventlog

将输出转换为字符串也非常简单,可以这样完成:
$result = geteventlog | Out-String

请注意,Out-String具有Width参数,该参数可控制结果输出的宽度。

关于string - Powershell如何将函数输出存储在字符串中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19639996/

相关文章:

powershell - 为什么 "F5 - Start Debugging"会忽略 PowerGUI 中的断点?

java - 从数学表达式字符串中提取数字

c - 对结构成员的字符串操作

powershell - 从 TFS 获取多版本差异报告?

powershell - INI文件逐行获取节

encoding - 输入编码 : accepting UTF-8

powershell - 使用 powershell 和 schtasks try catch 失败

c++ - 从NULL构造字符串?

string - kotlin 字符串中的两个并发字符串替换

powershell - 将pscustomobject传递到Start-Job脚本 block 时,为什么脚本属性丢失?