PowerShell

RDCMan 2.7 도메인 컴퓨터 원격데스크톱 연결 한방에 등록하기

delmaster 2016. 5. 3. 11:03

Remote Desktop Connection Manager 에 도메인에 가입된 모든 컴퓨터를 원격 데스크톱 연결로 일괄 등록할 수 있는 스크립트 입니다.

서버를 관리할때 각각의 서버들에 원격데스크톱 연결로 관리할때의 단점을 'Remote Desktop Connection Manager' (이하 RDCMan) 을 통해 조금더 간단하고 유연하게 관리가 가능한데 도메인에 서버 또는 관리할 컴퓨터가 많다면 등록하는 것 자체가 '일' 이 되겠지요.

기존에 만들어뒀던 [Software/Tools] - RDCMan 2.7 VM 콘솔연결 한방에 등록하기 를 약간 수정하여 도메인의 모든 컴퓨터를 일괄 등록할 수 있게 만들어 두었습니다.

아래의 파일을다운로드 받으신후, 해당파일 우클릭 > 'PowerShell에서 실행' 을 누르면 바탕화면에 도메인명.rdg 파일이 생성됩니다.

RDCMan에서 컴퓨터 리스트로 기본 디스플레이되는 목록은 'IP [호스트명]' 으로 되어지며, 각 컴퓨터 우클릭 > 'Properties' > 'Comment' 부분에는 해당 컴퓨터의 고유이름(DN)이 추가되게 되어있어 해당 컴퓨터가 Active Directory상의 어떤 경로에 위치해 있는지 알 수 있게 되어 있습니다.

 

 

 

 

아래는 해당 스크립트의 소스입니다.

 

<#
    내용: 도메인내 컴퓨터를 Remote Desktop connection Manager에 원격 데스크톱 연결 방식으로 일괄등록
    작성자: 이성환(www.delmaster.net)
    작성일 : 2016.04.29
 업데이트: 2016.04.29
   실행권한 확인후 관리자가 아닐시, 관리자 권한으로 자동 실행
  : 2016.05.02
   기존 파일 유무 확인후, 파일존재시 새로운 파일명으로 생성
#>

Function Permit-Check
{
   Param( [Security.Principal.WindowsBuiltinRole]$Role )
   $CurrentUser = [Security.Principal.WindowsPrincipal]([Security.Principal.WindowsIdentity]::GetCurrent())
   $CurrentUser.IsInRole($Role)
}

$Admin = Permit-Check "administrator"

Write-Host ""
Write-Host "======================www.delmaster.net=============================" -BackgroundColor Black -ForegroundColor White
Write-Host ""

Write-Host "관리자 권한 확인중.." -BackgroundColor Black -ForegroundColor Yellow

if ($Admin -eq "True")
{
 Write-Host "권한확인 성공" -BackgroundColor Black -ForegroundColor Red
 Write-Host ""

    $Path = "$env:userprofile\desktop"
    $Domain = Get-ADDomain
    $DomainName = $Domain.Forest
    Write-Host "현재 도메인에 가입된 컴퓨터를 $Path\$DomainName.rdg 파일로 저장합니다." -BackgroundColor Black -ForegroundColor Yellow
    Write-Host "작업중...." -BackgroundColor Black -ForegroundColor Red
    $TestPath = Test-Path $Path\$DomainName.rdg
       
    if ($TestPath -like "True")
    {
        Write-Host ""
        Write-Host "파일이 존재합니다!!" -BackgroundColor Black -ForegroundColor Red
        Write-Host "해당 경로에 새로운 파일을 생성합니다." -BackgroundColor Black -ForegroundColor Red
        Write-Host ""
        $random = random
        $DomainName = "$DomainName $random"
     }

    Get-ADComputer -Filter * -Properties * | select Name,IPv4Address,DistinguishedName | ? IPv4Address -NotLike "" | Export-csv -path $Path\$DomainName.rdg -encoding utf8
   
    $CompList = Get-Content $Path\$DomainName.rdg
    $CompGet = Import-Csv -Path $Path\$DomainName.rdg
    $CompCount = $CompGet.Count
         
    Write-Output "<?xml version=""1.0"" encoding=""utf-8""?>
    <RDCMan programVersion=""2.7"" schemaVersion=""3""><file><credentialsProfiles />
    <properties><expanded>True</expanded><name>$DomainName</name></properties>" > $Path\$DomainName.rdg
  
    for($i=0;$i -lt $CompCount; $i++)
    {
        $CompName = $CompGet.Name[$i]
        $CompIPv4 = $CompGet.IPv4Address[$i]
        $CompDesc = $CompGet.DistinguishedName[$i]
        Write-Output "<server><properties><displayName>$CompIPv4 [$CompName]</displayName>
        <name>$CompIPv4</name><comment>$CompDesc</comment></properties></server>" >> $Path\$DomainName.rdg
    }

    Write-Output "</file><connected /><favorites /><recentlyUsed /></RDCMan>" >> $Path\$DomainName.rdg
   
    $Encoding = Get-Content -Path $Path\$DomainName.rdg
    $Encoding | Out-File -Encoding utf8 -FilePath $Path\$DomainName.rdg

    Write-Host "모든 작업이 완료 되었습니다." -BackgroundColor Black -ForegroundColor Yellow
    Write-Host "$Path\$DomainName.rdg 파일을 확인하세요." -BackgroundColor Black -ForegroundColor Yellow
    Write-Host ""
    Write-Host "======================www.delmaster.net=============================" -BackgroundColor Black -ForegroundColor White
    Write-Host ""
  
 pause
}
else
{
 Write-Host "관리자 권한으로 실행되지 않았습니다." -ForegroundColor Yellow
 write-Host "현재 실행은 종료되며, 관리자 권한으로 자동 재실행 됩니다." -ForegroundColor Yellow
 sleep(1)
 Start-Process -Verb "Runas" -File PowerShell.exe -Argument "-STA -noprofile -file $($myinvocation.mycommand.definition)"
 Write-Host ""
    Write-Host "======================www.delmaster.net=============================" -BackgroundColor Black -ForegroundColor White
}

 

 

[참고글]