2014-09-22 48 views
0

我想在SCOM 2007中使用PowerShell在維護模式中安排URL列表。我試圖從文本文件中獲取URL列表名稱,並嘗試將其作爲輸入傳遞給下面的命令。但它不起作用。可一些身體幫助如何在文本文件傳遞的顯示名稱作爲輸入使用PowerShell將文本輸出轉換爲對象

$URLStuff = Get-Content C:\Display.txt 

$URLWatcher = (Get-MonitoringClass -name Microsoft.SystemCenter.WebApplication.Perspective) | 
    Get-MonitoringObject | where {$_.DisplayName -eq $URLStuff} 

回答

0

get-content將返回你一個String對象的數組,每行一個文件中找到。您需要打開where-object以搜索該陣列,查找從SCOM找到的每個對象的DisplayName

$URLWatcher = (Get-MonitoringClass -name Microsoft.SystemCenter.WebApplication.Perspective) | 
    Get-MonitoringObject | where {$URLStuff -contains $_.DisplayName} 

我假設你已經驗證了DisplayName確實包含你正在尋找的數據,並會匹配Display.txt內容。

+0

感謝您的幫助。我做了細微的修改和其現在的工作$ URLStuff =獲取內容C:\ Display.txt 的foreach($在$ URLStuff eachurl) { $類= GET-MonitoringClass -name Microsoft.SystemCenter.WebApplication。透視 $ URLWatcher = Get-MonitoringObject -monitoringclass:$ class |其中{$ eachurl -match $ _。DisplayName} – krishs27 2014-09-24 12:38:30