PowerShell WMI Alternate Credentials bug

 
Just a small post about a bug I ran into a few times already,
so you may not spend too much time trying to debug your script when in fact there’s nothing wrong with it:
 
 
There’s a known bug in PowerShell 1.0 when using WMI connections using alternate credentials to a remote machine.
For example, I was making a script to change the WINS client settings for a number of machines:
 
(Get-Wmiobject -comp MyServer -class "Win32_networkadapterconfiguration" -credential $creds | Where{$_.IpEnabled -Match "True"}).SetWinsServer("10.10.10.1","10.10.10.2")
 
The script failed with error: 0x80070005 (E_ACCESSDENIED)
because it was using the credentials the script was running with, not the credentials specified by the script.
 
The only way to fix this AFAIK, is to use Powershell 2.0 (CTP at this time so don’t use on production machines without care).
Or you can try running your entire script as an alternate user, but this isn’t very efficient if you want to run WMI commands against a large number of machines.
 
 
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s