2012-05-10 21 views
0

我需要您的幫助,使用Powershell中的變量。Powershell - 從變量中使用Get-StorageGroupCopyStatus

我想將Get-StorageGroupCopyStatus的結果放入一個變量中,然後能夠使用結果中的參數。

當我執行

Get-StorageGroupCopyStatus -Server server -StandbyMachine standbyserver 

返回幾個屬性,如「名稱」,「SummaryCopyStatus爲‘CopyQueueLength’,等等。 的事情是,我希望能夠通過操縱這些屬性爲了變量能夠使用它在一個IF語句,就像這樣:

$st = Get-StorageGroupCopyStatus -Server server -StandbyMachine standbyserver 

if ($st.SummaryCopyStatus -NotMatch "Healthy") 

發生了什麼事是,參數「.SummaryCopyStatus」無法通過變量‘$ ST’獲得

我在這裏錯過了什麼?

回答

0

試試這個,但我不能測試:

$Serv = Get-StorageGroupCopyStatus -Server server -StandbyMachine standbyserver 

$data = @() 

foreach ($item in $serv) 
{ 
$obj = new-object psObject 
$obj | Add-Member -membertype noteproperty -name "Name" -Value $item.StorageGroupName 
$obj | Add-Member -membertype noteproperty -name "CopyStatus -Value $item.SummaryCopyStatus 
$obj | Add-Member -membertype noteproperty -name "CopyQueueLength" -Value $item.CopyQueueLength 
$data += $obj 
} 

$data # contains the properties you added before. 
0

你可能找回對象的集合,你需要處理每一個,一次一個。獲取storge組對象,過濾出與你的qriteria不匹配的那些對象,然後對通過過濾的對象進行一些處理。

Get-StorageGroupCopyStatus -Server server -StandbyMachine standbyserver | 
Where-Object { $_.SummaryCopyStatus -NotMatch "Healthy" } | 
Foreach-Object { "do you stuff here" }