I\'ve tried enclosing the following in an if statement so I can execute another command if this succeeds:
Get-WmiObject -Class Win32_Share -ComputerName $Ser
you can try :
$res = get-WmiObject -Class Win32_Share -Filter "Description='Default share'" if ($res -ne $null) { foreach ($drv in $res) { $Localdrives += $drv.Path } } else { # your error }