title: Returning a Row Count for a DataRow in PowerShell
body: <p>My script is populating a datarow from a stored procedure in SQL Server. I then reference specific columns in this datarow throughout the script. What I'm trying to do is add functionality that takes action X if the row count = 0, action Y if the row count = 1, and action Z if the row count > 1. </p>
  
  <pre><code>-- 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
  }
  </code></pre>
  
  <p>I can get $MyResult.Count to work if I'm using an array, but then I can't reference $MyRow.FileName directly.</p>
  
  <p>This is probably pretty simple, but I'm new to PowerShell and object-oriented languages. I've tried searching this site, The Scripting Guy's blog, and Google, but I haven't been able to find anything that shows me how to do this.</p>
  
  <p>Any help is much appreciated. </p>