Search code examples
powershellpowershell-3.0

Convert LineNumber to int


I'm trying to use the output as variable from this:

  $start=Get-Content C:\iampx_v4.6\c.txt | Select-String 'tvg-name="MI:'| Select-Object -First 1 | Select-Object LineNumber

So fo example the output is:

LineNumber
----------
404

Now I want to use it here:

$conToDel = Get-Content C:\iampx_v4.6\c.m3u
$conToDel | 
  ForEach-Object { 
    if ($_.ReadCount -ge 1 -and $_.ReadCount -le $start) { 
      $_ -replace '.','' 
    } else { 
      $_ 
    } 
  } | 

But for this I need to cast first the line number to int and I only can ToString...


Solution

  • Try :

    $start = Get-Content C:\iampx_v4.6\c.txt | 
       Select-String 'tvg-name="MI:'| 
       Select-Object -First 1 | 
       Select-Object -ExpandProperty LineNumber