Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell远程处理启用代理服务器_Powershell_Proxy_Powershell Remoting - Fatal编程技术网

使用Powershell远程处理启用代理服务器

使用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

我正在尝试使用PowerShell远程处理将代理服务器添加到远程服务器(ServerB)。但是,每次设置代理后,代理都会被清除。以下是我使用的代码:

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:设置只能在远程会话期间持续。