Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Convert object to string then to int

$
0
0

Hi all so right now I reading a log file and selecting the line numbers where a certain symbol appears. The symbol is a "/" that appears every day when the script is run. I then store the second line number in a variable . However this is still an object and not an int so right now I am using substring to get the numbers out of the object and then casting it to an int. I've tried using out-string with no luck, is there any better way to do this? Thanks.

Current Code:

$alllines = Select-String -Pattern "/" -path C:\users\Public\Documents\www\2ndlog.log | Select-Object linenumber
$line = [string]$alllines[2]
$line = $line.Substring(13,2)
$line = [int]$line
$line = $line - 1

What I've tried

$alllines = Select-String -Pattern "/" -path C:\users\Public\Documents\www\2ndlog.log | Select-Object linenumber
$line = $alllines[2] 
$line = $line | Out-String
$line = [int]$line


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>