Because I often perform operations in Working Group mode, you must enter creden。 when Remotely Managing other hosts. Generally, Get-Credential is used to pop up a prompt box and enter the password.
For example:
$ C = Get-Credential DBA_User
Get-WmiObject-Credential $ c-Class Win32_LogicalDisk-ComputerName 10.0.0.10
It is okay to query only one remote host. to query many hosts, you have to enter the password multiple times. A little troublesome!
So I thought I could not save the user name and password and call them directly. There are still methods:
$ Uname = "DBA_User"
$ Pwd = convertid-SecureString "My_Pwd"-AsPlainText-Force;
$ Cred = New-Object System. Management. Automation. PSCredential ($ uname, $ pwd );
Get-WmiObject-Credential $ cred-Class Win32_LogicalDisk-ComputerName 192.168.1.111
Everything in PowerShell is an object. Of course, Get-Credential is no exception. Instantiate an object and call it later.
The password must be converted to SecureString.