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
Post a Comment