I have a script that is supposed to select a usb hard drive based on the label. I'm getting a strange error all of a sudden when it used to work just fine. I suspect maybe some code needs to change since an update or something? Anyways, here's the code. What am I doing wrong?
get-wmiobject -class "Win32_Volume" -namespace "root\cimv2" -computername dpm | where-object {$_.Label -and (($_.Label).substring(0,8) -eq "Off Site")}
It's returning the following:
Exception calling "Substring" with "2" argument(s): "Index and length must refer to a location within the string. Parameter name: length" At line:2 char:50+ where-object {$_.Label -and (($_.Label).substring <<<< (0,8) -eq "Off Site")}+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : DotNetMethodException
Thanks in advance.