Get current user's credentials object in Powershell without prompting

前端 未结 4 1713
迷失自我
迷失自我 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:57

    "Trying [System.Net.CredentialCache]::DefaultNetworkCredentials shows a blank, and [System.Security.Principal.WindowsIdentity]::GetCurrent() doesn't provide the object or information I need."

    You already have your answer. I use this to pass the currently logged in user's credentials along in several scripts:

    $Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
    $Username = $Credentials.UserName
    $Password = $Credentials.Password
    

    If you try to dump them to any kind of readable output, those values are empty when you dump them (for obvious security reasons), however they do work where you need a PSCredential object.

提交回复
热议问题