Powershell 代理设置

Powershell Proxy setting

使用这个 cmdlet,我可以检查我在 powershell 中的代理设置:

$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$proxyServer = Get-ItemProperty -Path $regKey
$proxyServer | fl *proxy*

或使用此 cmdlet:

Get-ItemProperty Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | Select-Object *Proxy*

我的问题是,如何获取另一个网络用户的代理设置?

Enter-PsSession -Computername "nameofcomputer" | 
Get-ItemProperty Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings' | Select-Object *Proxy*

然而,这需要 WinRM 服务在目标主机上 运行。

如果 WinRM 不是 运行,它可能 运行 作为登录脚本输出文件 "someplace\output.txt" 然后共享该文件夹以获取数据。

Invoke-Command 你可能会更好。在远程 PSSession 中获取对象和变量会限制您在该会话中使用这些项目。你应该这样做:

$Session = New-PSSession -ComputerName "WkStn01"
$SB = {
    Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' `
        | Select-Object *Proxy*
}

$ProxySettings = Invoke-Command -Session $Session -ScriptBlock $SB

找出用户当前登录的计算机是一个更大的问题,需要花费更多的精力,因此最好知道他们正在使用的计算机的名称。