如何组合这两个powershell脚本行?

如何组合这两个powershell脚本行?,powershell,Powershell,我对powerscript非常陌生,我甚至不知道该问什么问题,所以我甚至无法搜索我想象中的常见问题 我有: $temp=$_|Select-String 'Game started at: (.*?)\n' $timestamp=$temp.matches[0].groups[1].value 我试过: $timestamp=$_|Select-String 'Game started at: (.*?)\n'.matches[0].groups[1].value 及 这没用 如何正确地将这

我对powerscript非常陌生,我甚至不知道该问什么问题,所以我甚至无法搜索我想象中的常见问题

我有:

$temp=$_|Select-String 'Game started at: (.*?)\n'
$timestamp=$temp.matches[0].groups[1].value
我试过:

$timestamp=$_|Select-String 'Game started at: (.*?)\n'.matches[0].groups[1].value

这没用


如何正确地将这两行合并为一行?

我不知道您的管道对象(
$)\uu
最初是什么,但请尝试以下方法:

$timestamp = $_| Select-String 'Game started at: (.*?)\n' | % { $_.Matches[0].groups[1].value }
Select String
将数组作为结果进行管道传输,因此您需要使用foreach循环(%is short alias)循环遍历每个字符串,即使它只是一个字符串,并获取所需的值

$timestamp = $_| Select-String 'Game started at: (.*?)\n' | % { $_.Matches[0].groups[1].value }