powershell - 从 foreach/select 结果中只获取一个字符串

标签 powershell powershell-2.0 powershell-3.0 powershell-4.0

Select-String -Path 'C:\Users\Public\Desktop\hs-source.txt' -list  '\bhttp\:\/\/www\.hs\-scene\.to\/wbb4\/index\.php\/Thread\/(?:(?!Neuerscheinungen)(?:.|\n))*Neuerscheinungen-((?:Jan(?:uar)?|Feb(?:ruar)?|Mär(?:z)?|Apr(?:il)?|Mai|Jun(?:i)?|Jul(?:i)?|Aug(?:ust)?|Sep(?:tember)?|Sept|Okt(?:ober)?|Nov(?:ember)?|Dez(?:ember)?))(-20\d{2})'  | foreach-object  {$_.matches} | select value 

给我这个结果:

Value
----                                                                      
http://www.hs-scene.to/wbb4/index.php/Thread/42042-H%C3%B6rbuch-Neuerscheinungen-August-2015 

如何只得到链接,而没有值和笔画? 我想在脚本的下一部分中使用该链接。 感谢您的回答。

最佳答案

将最终的管道命令更改为:

| select -ExpandProperty value

否则 value 仍然是对象的一个​​ property,它恰好是您选择的唯一属性。您需要使用 $obj.value 访问它,而不使用 -ExpandProperty 开关

关于powershell - 从 foreach/select 结果中只获取一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835139/

相关文章:

powershell - foreach循环修改变量

Powershell 'x or y' 分配

powershell - 从Powershell启动Elevated CMD.exe

Powershell 压缩文件夹和文件,然后删除旧文件

azure - 从 Azure 存储 Blob 中批量删除早于 'x' 天的对象

powershell - 如何使用 powershell 将文件从一个 Blob 存储容器移动到另一个 Blob 存储容器

windows - 如何将 MS .NET Framework 4 添加到 Windows Server 更新服务?

powershell - CSV文件按col1分组并显示col2的最大值

windows - powershell 2.0重定向文件句柄异常

windows - 如何在具有多个输出的Invoke-Command中使用多个命令