I have a powershell script that calls Get-WmiObject
with -Credential
. However, this errors out if I am running it against the local machine:
Get-WmiObject : User credentials cannot be used for local connections
What is the proper way to add an if localhost logic to avoid this error? Or is there a better way?