putty导出服务器文件,如何导出/导入PuTTy会话列表?

dwurf..

43

当我尝试其他解决方案时,我收到此错误:

Registry editing has been disabled by your administrator.

Phooey,我说!

我将以下powershell脚本放在一起,用于导出和导入PuTTY设置.导出的文件是一个windows .reg文件,如果您有权限将导入干净,否则使用import.ps1加载它.

警告:像这样弄乱注册表是一个坏主意™,我真的不知道我在做什么.使用以下脚本需要您自担风险,并准备好让您的IT部门重新映像您的计算机并向您询问有关您正在做什么的不舒服的问题.

在源机器上:

.\export.ps1

在目标机器上:

.\import.ps1 > cmd.ps1

# Examine cmd.ps1 to ensure it doesn't do anything nasty

.\cmd.ps1

export.ps1

# All settings

$registry_path = "HKCU:\Software\SimonTatham"

# Only sessions

#$registry_path = "HKCU:\Software\SimonTatham\PuTTY\Sessions"

$output_file = "putty.reg"

$registry = ls "$registry_path" -Recurse

"Windows Registry Editor Version 5.00" | Out-File putty.reg

"" | Out-File putty.reg -Append

foreach ($reg in $registry) {

"[$reg]" | Out-File putty.reg -Append

foreach ($prop in $reg.property) {

$propval = $reg.GetValue($prop)

if ("".GetType().Equals($propval.GetType())) {

'"' + "$prop" + '"' + "=" + '"' + "$propval" + '"' | Out-File putty.reg -Append

} elseif ($propval -is [int]) {

$hex = "{0:x8}" -f $propval

'"' + "$prop" + '"' + "=dword:" + $hex | Out-File putty.reg -Append

}

}

"" | Out-File putty.reg -Append

}

import.ps1

$input_file = "putty.reg"

$content = Get-Content "$input_file"

"Push-Location"

"cd HKCU:\"

foreach ($line in $content) {

If ($line.StartsWith("Windows Registry Editor")) {

# Ignore the header

} ElseIf ($line.startswith("[")) {

$section = $line.Trim().Trim('[', ']')

'New-Item -Path "' + $section + '" -Force' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }

} ElseIf ($line.startswith('"')) {

$linesplit = $line.split('=', 2)

$key = $linesplit[0].Trim('"')

if ($linesplit[1].StartsWith('"')) {

$value = $linesplit[1].Trim().Trim('"')

} ElseIf ($linesplit[1].StartsWith('dword:')) {

$value = [Int32]('0x' + $linesplit[1].Trim().Split(':', 2)[1])

'New-ItemProperty "' + $section + '" "' + $key + '" -PropertyType dword -Force' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }

} Else {

Write-Host "Error: unknown property type: $linesplit[1]"

exit

}

'Set-ItemProperty -Path "' + $section + '" -Name "' + $key + '" -Value "' + $value + '"' | %{ $_ -replace 'HKEY_CURRENT_USER\\', '' }

}

}

"Pop-Location"

为非惯用代码道歉,我对Powershell不是很熟悉.欢迎改进!

工作得很好,节省时间.其中除了......我在这里按照说明来安装权限:http://stackoverflow.com/questions/4037939/powershell-says-execution-of-scripts-is-disabled-on-this-system. (3认同)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值