提问人:Ulkarsh Devasia 提问时间:4/13/2015 最后编辑:John SaundersUlkarsh Devasia 更新时间:1/12/2021 访问量:1612
使用 Powershell 远程处理启用代理服务器
Enabling Proxy server using Powershell remoting
问:
我正在尝试使用PowerShell Remoting将代理服务器添加到远程服务器(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
如果我登录到服务器并从那里运行它,上面的代码对我来说工作得很好。
答: 暂无答案
评论