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
Or if a failure returns no standard output, that would work for an if statement:
if (! (Get-CimInstance Win32_Share -ComputerName $Server.name -Credential $credentials -Filter "Description='Default share'")) {
'command failed'
}
Also there's now the or symbol "||" in powershell 7:
Get-CimInstance Win32_Share -ComputerName $Server.name -Credential $credentials -Filter "Description='Default share'" || 'command failed'