Share via


Get-wmiobject prompting for password issues

Question

Wednesday, January 26, 2011 8:06 PM

hi, i am using get-wmiobject to connect to remote computer rand get some drive info using the following commmand 

Get-WmiObject -ComputerName $computer -credential XYZ Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}

 

running the above command prompts me for password, how can i stop the prompt and hardcode it in script...

 

Thanks

Saurabh

All replies (1)

Thursday, January 27, 2011 6:03 AM ✅Answered

Hi,

 

Use the following scripts to store the password in a credential.

 

#Store the password in credential#

 

Read-host -assecurestring | convertfrom-securestring | out-file C:\cred.txt

$password = get-content C:\cred.txt | convertto-securestring

$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist "myusername",$password

 

#Run the scripts to get drive info.

 

Get-WmiObject -ComputerName $computer -credential $credential Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3}

 

Reference:

 

Powershell Tip - Storing and Using Password Credentials

 

Best Regards

Dale

 

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”