Check Whether drive exists and find the capacity
hi ,
i wrote script check d drive exists , if exist should give size of d drive here script :-
$check = "d:\" $testobj=get-wmiobject win32_volume -filter "driveletter= 'd:'"
$caption= $testobj.caption
if($check -match $caption ) { write-output " true" $cap= $testobj.capacity $capsize= $([math]::round($($cap/1gb), 2))
write-output " capacity $capsize" }
else
{ write-output "$check doesnt exist" }
i error :-
bad argument operator '-match': parsing "d:\" - illegal \ @ end of pattern.
.
at line:7 char:18
+ if ($check -match <<<< $caption )
+ categoryinfo : invalidoperation: (:) [], runtimeexception
+ fullyqualifiederrorid : badoperatorargument
i tried -like string worked on local machine , not working on windows server 2008 r2. please help.
if($check -match [regex]::escape($caption) )
Windows Server > Windows PowerShell
Comments
Post a Comment