 <p>Are you sure <code>$s</code> is a string and not an array? If it is an array, <code>$s.Length</code> will be the number of elements in the array and you could get the error that you are getting.</p> <p>For example:</p> <pre><code>PS &gt; $str = @("this", "is", "a") PS &gt; $str.SubString($str.Length - 1) Exception calling "Substring" with "1" argument(s): "startIndex cannot be larger than length of string. Parameter name: startIndex" At line:1 char:1 + $str.SubString($str.Length - 1) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException </code></pre>