Get-wmiobject prompting for password issues


hi, using get-wmiobject connect remote computer rand drive info using following commmand 

get-wmiobject -computername $computer -credential xyz win32_logicaldisk | where-object {$_.drivetype -eq 3}

 

running above command prompts me password, how can stop prompt , hardcode in script...

 

thanks

saurabh

hi,

 

use following scripts store password in credential.

 

#store 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 scripts drive info.

 

get-wmiobject -computername $computer -credential $credential win32_logicaldisk | where-object {$_.drivetype -eq 3}

 

reference:

 

powershell tip - storing , using password credentials

 

best regards

dale

 


please remember click “mark answer” on post helps you, , click “unmark answer” if marked post not answer question. can beneficial other community members reading thread. ”


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Group Policy Event ID 1058 Error Code 1326 (The user name or password is incorrect)

Suspicious event log Event ID: 4905

DCOM received error "2147746132" from...