Unable to get CSV Row count in Powershell Unable to get CSV Row count in Powershell powershell powershell

Unable to get CSV Row count in Powershell


when you have ONE data row in a CSV file, the import produces a single object. that has a known bug in that it will report zero as the .Count of the $Var. this appears to happen with anything that returns a single PSCustomObject - but i aint sure of that.

the solution is to force it to be an array. you can cast it as [array] or simply wrap it in @(). using your code for an example ...

$markdownlinkstoProcess = Import-Csv $markdownlink -Delimiter ","$markdownlinkstoProcess.GetType()# result = PSCustomObject$markdownlinkstoProcess.Count# result = 0$markdownlinkstoProcess = @(Import-Csv $markdownlink -Delimiter ",")$markdownlinkstoProcess.GetType()# result = Object[]$markdownlinkstoProcess.Count# result = 1