使用Powershell远程处理启用代理服务器
我正在尝试使用PowerShell远程处理将代理服务器添加到远程服务器(ServerB)。但是,每次设置代理后,代理都会被清除。以下是我使用的代码:使用Powershell远程处理启用代理服务器,powershell,proxy,powershell-remoting,Powershell,Proxy,Powershell Remoting,我正在尝试使用PowerShell远程处理将代理服务器添加到远程服务器(ServerB)。但是,每次设置代理后,代理都会被清除。以下是我使用的代码: Invoke-command -computername ServerB -authentication Negotiate -scriptblock{$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" $proxyServer
Invoke-command -computername ServerB -authentication Negotiate -scriptblock{$regKey="HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings"
$proxyServer = ""
$proxyServerToDefine = 'our.proxy.server:port'
$proxyServer = Get-ItemProperty -path $regKey ProxyServer -ErrorAction SilentlyContinue
if([string]::IsNullOrEmpty($proxyServer))
{
Set-ItemProperty -path $regKey ProxyServer -value $proxyServerToDefine
Set-ItemProperty -path $regKey ProxyEnable -value 1
#The only way I've found to get the proxy settings to apply is to start ie in some way.
$ie = New-Object -ComObject internetexplorer.application
$ie.Quit()
Remove-Variable -Name ie
Write-Verbose "Proxy is now enabled"
}
else
{
Write-Verbose "Proxy Server already present"
}
}
在我实例化“ie”对象后,代理将被清除。
我已尝试通过在PowerShell远程会话中运行上述代码(代理启用代码部分)(使用Enter PSSession
)来启用代理,但这并没有解决我的问题
如果我登录到服务器并从那里运行,以上代码对我来说很好。我注意到您正在使用HKCU:设置代理,您是否尝试过在HKLM:中设置代理?根据您的配置文件设置和组策略,HKCU:设置只能在远程会话期间持续。