SAPIEN Solutions

SAPIEN homepage
PrimalScript script editor+ide
PrimalScope script debugger
Free Tools script utilities
SAPIEN Press tech books
ScriptingAnswers.com learn+share
ScriptingOutpost.com online store
Blog.Sapien.com official blog
Contact Us

 

WMI and alternate credentials

 Here’s an example of using PowerShell to connect to WMI on a remote computer using alternate credentials. Keep in mind that WMI itself doesn’t permit alternate credentials for local connections.

 

  1. #
  2. # ScriptingAnswers.com Essentials
  3. # copyright 2006 SAPIEN Technologies, Inc.
  4. #
  5. # Using alternate credentials with WMI
  6. #

  7. # get credential - graphical prompt
  8. $cred = Get-Credential

  9. # alternately, only prompt for password:
  10. # $cred = get-credential "DOMAIN\USERNAME"

  11. # can't use alt credentials against local machine
  12. # so be sure to specify a remote computer

  13. # get all instances of a class
  14. $wmi = Get-WmiObject Win32_Service -comp "ServerA" -cred $cred

  15. # execute a query
  16. $wmi = Get-WmiObject -query "SELECT * FROM Win32_Process" -comp "ServerA" -cred $cred
It’s probably worth noting that the Get-Credential call will prompt you for a password in a dialog box - there’s really no way, for security reasons, to include the password on the command-line. It’s how PowerShell is designed.

 

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: , ,

Leave a Reply


Entries (RSS) and Comments (RSS).