在远程计算机上提取和导出注册表值

时间:2013-09-24 08:47:02

标签: powershell

我试图找出哪些计算机仍设置为通过代理服务器连接到Internet。 因此,我尝试在AD中读取值ProxyServer和Proxy Enabled值。 在互联网上搜索后,我想出了这个:

$computername = Get-Content -path ".\pclist2.txt"

if (test-connection -computername $computername -quiet)
{
foreach ($pc in $computername)
    {
    $loggedon =@(Get-WmiObject -ComputerName $pc -Namespace root\cimv2 -Class Win32_ComputerSystem)[0].UserName; 

    #IEKeys
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $pc.computer)
    $regkey = $reg.OpenSubkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
    $LMPS = $regkey.GetValue("ProxyServer")
    $LMPE = $regkey.GetValue("ProxyEnable")
    $reg2 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('CurrentUser', $pc.computer)
    $regkey2 = $reg2.OpenSubkey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings")
    $CUPS = $regkey2.GetValue("ProxyServer")
    $CUPE = $regkey2.GetValue("ProxyEnable")
    Add-Content ".\IEproxies.csv" "$pc;$LMPS;$LMPE;$CUPS;$CUPE"
    }
}

不幸的是,只有CurentUser的ProxyEnable变量才会导出到该文件中。 其他值为空,我没有收到运行脚本的错误消息。 有人可以帮我这个吗?

提前,

亨利

0 个答案:

没有答案
相关问题