Pass password into -credential

后端 未结 3 580
一向
一向 2021-02-05 13:15

I am trying to login into a computer. I have been playing with various versions and determined that my past questions were when I didn\'t know what I was really trying to do.

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-05 13:21

    WOW I figured it out thanks to https://social.technet.microsoft.com/forums/windowsserver/en-US/440ab7ed-7727-4ff7-a34a-6e69e2dff251/getwmiobject-prompting-for-password-issues

    So I didn't realize I can use the $MySecureCreds as the -credential

    ANSWER:

    $Username = 'domain\username'
    $Password = 'password'
    $pass = ConvertTo-SecureString -AsPlainText $Password -Force
    
    $SecureString = $pass
    # Users you password securly
    $MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString 
    
    gwmi win32_service –credential $MySecureCreds –computer PC#
    

提交回复
热议问题