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

Powershell script to select drive based on label

$
0
0

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.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



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