troubleshooting Question

Powershell Script Finds First Result and Quits With Error

Avatar of Bob
BobFlag for United States of America asked on
2 Comments2 Solutions102 ViewsLast Modified:
This stops on the first line where it finds the "@" and does not continue through the remainder of the text file. Also, when it does complete and gives me the first value that I am looking (120155) for and has an error I am not familiar with.

Cannot find an overload for "indexOf" and the argument count: "2".
At line:4 char:1
+ $end = $str.indexOf(",@", $start)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
Exception calling "Substring" with "2" argument(s): "startIndex cannot be larger than length of string.
Parameter name: startIndex"
At line:7 char:1
+ $result = $str.substring($start, $length)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ArgumentOutOfRangeException

PS H:\>

$str = Get-Content C:\Temp\Verify_Integrations\INT_integrations_post2.txt -Encoding Ascii
$start = $str.indexOf("@") + 1
$end = $str.indexOf(",@", $start)
$length = $end - $start
$result = $str.substring($start, $length)


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros