我的腳本正在SQL Server中的存儲過程中填充數據行。然後在整個腳本中引用此數據表中的特定列。我想要做的就是添加的功能,採取措施X如果行數= 0,動作Y如果行數= 1,並採取行動Z如果行計數> 1在PowerShell中返回DataRow的行數
-- PowerShell script snippet
# $MyResult is populated earlier;
# GetType() returns Name=DataRow, BaseType=System.Object
# this works
ForEach ($MyRow In $MyResult) {
$MyFile = Get-Content $MyRow.FileName
# do other cool stuff
}
# this is what I'm trying to do, but doesn't work
If ($MyResult.Count -eq 0) {
# do something
}
ElseIf ($MyResult.Count -eq 1) {
# do something else
}
Else {
# do this instead
}
我能得到$ MyResult.Count工作,如果我使用一個數組,但然後我不能直接引用$ MyRow.FileName。
這可能很簡單,但我是PowerShell和麪向對象語言的新手。我試過搜索這個網站,腳本專家的博客和谷歌,但我一直沒有找到任何能夠告訴我如何做到這一點的東西。
任何幫助,非常感謝。
檢查'$ MyResult | Get-Member'來查看對象提供的方法和屬性。 – 2013-03-13 20:31:35
謝謝你回覆,Ansgar。我應該提到我查看過這些內容,並且發現可以執行$ MyResult.ItemArray.Count,但它返回了所有列和行的計數。因此,如果計算> 0,它無法找到計數是否爲1。 – sqlfool 2013-03-13 20:42:33
$ MyResult.rows.Count是否有效? – FilamentUnities 2013-03-13 21:45:48