2015-09-28 98 views
0

我打算用很多不同的輸出格式的PowerShell語句。而且我只需要一個控制檯應用程序中所有輸出的數據(實際上就是一個windows應用程序),我想用linq來查詢數據,因爲Trim將會非常成功。搜索結果在PowerShell的輸出

任何想法,就像將輸出傳遞給文本文件,並將linq與此文本文件一起使用,但這種做法效果不佳。

例如 我如何不同使用LINQ或另一招

# 
# Script.ps1 
# 
param([string]$strComputer = ".") 

Get-Process | 
    Where-Object {$_.MainWindowTitle -ne ""} | 
    Select-Object MainWindowTitle | 
    Out-String -stream 
+2

你想要做什麼? –

+0

我認爲他正試圖用C#與LINQ重寫這個PowerShell腳本 – 2015-09-28 11:31:25

回答

0

在這個小腳本任意類型窗口的相關輸出basicaly搜索工具涉及select-string cmdlet

因爲它是很難告訴你想做什麼,這裏有一些樣品

$results=Get-Process | 
    Where-Object {$_.MainWindowTitle -ne ""} | 
    Select-Object MainWindowTitle | 
    Out-String -stream 
$results |select-string "notepad" #process containing the word notepad 
$results |select-string "\d{2}" #process with 2 digits 
+0

謝謝。這是一個部分解決方案。我認爲從這裏我可以一個人繼續。 我會調查更多關於選擇字符串 – Pablo