使用登录 windows 机器的用户凭据从 Powershell 执行 REST API 请求(AD 凭据)

Execute a RESTAPI request from Powershell using the credentials of the user logged into the windows machine(AD Credential's)

我想 login/communicate 使用 RESTAPI 连接到远程系统,并且我想使用与从 windows 机器启动脚本的用户相同的 AD 凭据。 例子:- 我使用凭据 "Domain\User" 和密码 "password" 登录到 Windows 服务器,并希望使用相同的凭据登录远程系统而不输入用户名和密码。

尝试使用 WebClient class:

$webClient = new-object System.Net.WebClient
$webClient.UseDefaultCredentials = $true
$reply = $webClient.DownloadString("http://google.com")
$reply

这里主要是把WebClientUseDefaultCredentials属性设置为true。 方法 DownloadString 只是如何使用 WebClient 的示例。根据您的 REST 端点,您可以使用许多其他方法。您可以找到完整列表 here.