tech.guitarrapc.cóm

Technical updates

Remote Desktop Connection Managerのすすめ

Remote Desktop Connection Managerご存じの方も多い複数のRemote Desktop接続をツリー上に管理できるMS謹製のツールです。

今回は、 Windowsを使っていてRemote Desktop (mstsc) を利用する方におすすめのこれを紹介します。 複数のWindowsサーバー管理をするに当たり、 CUIはPowerShellでいけます。

GUIはやはり大多数でRemote Desktopが主流ですが、一例として。 使っているスクリプトをおいておきます。

guitarrapc/PowerShellUtil - Install-RemoteDesktopConnectionManager | GitHub

ダウンロード

MS公式からどうぞ。

Remote Desktop Connection Manager

インストール

ダウンロードしたファイルの実行でインストールできます。 ダウンロードしたファイルをcmdで /? 付きで実行するとヘルプが出て、自動インストール可能なことが分かります。

RDCMan.msi /?

これを利用してみます。

Windows ® Installer. V 5.0.9200.16384

msiexec /Option <Required Parameter> [Optional Parameter]

Install Options
    </package | /i> <Product.msi>
        Installs or configures a product
    /a <Product.msi>
        Administrative install - Installs a product on the network
    /j<u|m> <Product.msi> [/t <Transform List>] [/g <Language ID>]
        Advertises a product - m to all users, u to current user
    </uninstall | /x> <Product.msi | ProductCode>
        Uninstalls the product
Display Options
    /quiet
        Quiet mode, no user interaction
    /passive
        Unattended mode - progress bar only
    /q[n|b|r|f]
        Sets user interface level
        n - No UI
        b - Basic UI
        r - Reduced UI
        f - Full UI (default)
    /help
        Help information
Restart Options
    /norestart
        Do not restart after the installation is complete
    /promptrestart
        Prompts the user for restart if necessary
    /forcerestart
        Always restart the computer after installation
Logging Options
    /l[i|w|e|a|r|u|c|m|o|p|v|x|+|!|*] <LogFile>
        i - Status messages
        w - Nonfatal warnings
        e - All error messages
        a - Start up of actions
        r - Action-specific records
        u - User requests
        c - Initial UI parameters
        m - Out-of-memory or fatal exit information
        o - Out-of-disk-space messages
        p - Terminal properties
        v - Verbose output
        x - Extra debugging information
        + - Append to existing log file
        ! - Flush each line to the log
        * - Log all information, except for v and x options
    /log <LogFile>
        Equivalent of /l* <LogFile>
Update Options
    /update <Update1.msp>[;Update2.msp]
        Applies update(s)
    /uninstall <PatchCodeGuid>[;Update2.msp] /package <Product.msi | ProductCode>
        Remove update(s) for a product
Repair Options
    /f[p|e|c|m|s|o|d|a|u|v] <Product.msi | ProductCode>
        Repairs a product
        p - only if file is missing
        o - if file is missing or an older version is installed (default)
        e - if file is missing or an equal or older version is installed
        d - if file is missing or a different version is installed
        c - if file is missing or checksum does not match the calculated value
        a - forces all files to be reinstalled
        u - all required user-specific registry entries (default)
        m - all required computer-specific registry entries (default)
        s - all existing shortcuts (default)
        v - runs from source and recaches local package
Setting Public Properties
    [PROPERTY=PropertyValue]

Consult the Windows ® Installer SDK for additional documentation on the
command line syntax.

Copyright © Microsoft Corporation. All rights reserved.
Portions of this software are based in part on the work of the Independent JPEG Group.

共有フォルダなどにおいたインストーラーを使って、PowerShellでインストールしましょう。 インストールにおいて、 RDCMan.msiをTempにコピーしてRemote Desktop Connection Managerのインストーラを実行するようにしています。 ファイル名はInstall-RemoteDesktopConnectionManager.ps1とでもして保存します。

実行前に$pathへインストーラをおいたパスを指定します。

# Define
$software = "RDCMan.msi"
$path = Join-Path "Path to Installer (c:\hogehoge)" $software
$destination = Join-Path "C:\Windows\Temp" $software

# run
if (Test-Path $path)
{
    try
    {
        # Copy Software
        Copy-Item -Path $path -Destination $destination -Force -ErrorAction Stop
    }
    catch
    {
        throw $_
    }

    # install Software
    if (Test-Path $destination)
    {
        try
        {
            Start-Process -FilePath $destination -ArgumentList "/m /quiet /passive"
            Write-Host "Installation Complete" -ForegroundColor Cyan
        }
        catch
        {
            throw $_
        }
    }
    else
    {
        Write-Warning "$destination not found!"
    }
}
else
{
    Write-Warning "$path not found!"
}

スクリプトをおいたら、右クリックでPowerShellでインストールします。 以下のバッチコマンドを上記のRemoteDesktopConnectionMangerインストール用PowerShell Scriptと同一パスにおくとバッチファイルダブルクリックで実行できます。

pushd %~dp0
powershell -File ".\Install-RemoteDesktopConnectionManager.ps1"
pause

設定の共有

Remote Desktop Connection Managerは、接続設定などを共有可能です。 パスワードなどを保持するのもアレなので社内ポリシーに従って貰うとしてできることはできるということで。

設定ファイルは、XMLで.rdgファイルに保持されています。 一定の規則を持った複数の接続先がある場合、直接xmlを生成するPowerShellコードを作って追記できます。

特定のIP末尾で作りたい例です。

function Add-RemoteDesctopConnectionManagerServers{

    param(
        [string[]]
        $servers
    )

    $result = @()

    foreach($server in $servers)
    {
        $result += "        <server>"
        $result += "            <name>192.168.0.$server</name>"
        $result += "            <displayName>192.168.0.$server</displayName>"
        $result += "            <comment />"
        $result += '            <logonCredentials inherit="FromParent" />'
        $result += '            <connectionSettings inherit="FromParent" />'
        $result += '            <gatewaySettings inherit="FromParent" />'
        $result += '            <remoteDesktop inherit="FromParent" />'
        $result += '            <localResources inherit="FromParent" />'
        $result += '            <securitySettings inherit="FromParent" />'
        $result += '            <displaySettings inherit="FromParent" />'
        $result += "        </server>"
    }

    return $result
}

実行時はこのようなかんじで。

Add-RemoteDesctopConnectionManagerServers -servers $(10..20)
Add-RemoteDesctopConnectionManagerServers -servers $(30..35)

Remote Desktop Connection ManagerからFile > Openで、接続設定xmlを追加できるので是非どうぞ。