Get current user's credentials object in Powershell without prompting

前端 未结 4 1707
迷失自我
迷失自我 2020-11-29 07:38

I have a Powershell script that is going to be run through an automation tool against multiple servers. It works fine on Windows machines, as the remote calls use the tool\'

4条回答
  •  旧巷少年郎
    2020-11-29 07:48

    How about encrypting the password using the service account's encryption key?

    A quick example:

    Run PowerShell as the service account, run the following and save the output to a text file (or embed it in the scheduled task call):

    $String = ''
    ConvertFrom-SecureString -SecureString (ConvertTo-SecureString -String $String -AsPlainText -Force)
    

    Use the following in your scheduled task in order to decrypt and utilize the password:

     $EncryptedString = ''
     [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((ConvertTo-SecureString -String $EncryptedString)))
    

    That should do the trick. You cannot reuse the encrypted password on a different computer, though, or if you for whatever reason destroy you local key store :)

提交回复
热议问题