<# 내용: 로컬 컴퓨터의 Hyper-V VM을 'Remote Desktop Connection Manager'의 'VM Console Connec' 으로 등록 작성자 : 이성환(www.delmaster.net) 작성일 : 2015.12.21 업데이트: 2016.04.08 : 생성되는 RDG 파일의 이름을 '로컬컴퓨터의이름-Hyper-V.rdg'로 생성되도록 수정 업데이트: 2016.04.20 : 스크립트 실행 권한을 관리자 권한으로 자동 변경되게 수정 상기 내용을 삭제한 무단 배포는 금지 합니다. (상기 내용 포함한 배포 허용) #> 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 "" $PathTest = "False" while($PathTest -lt "Ture") { Write-Host "rdg파일이 저장될 경로를 입력합니다." -BackgroundColor Black -ForegroundColor yellow Write-Host "경로에 띄어쓰기가 있어도 무방합니다." -BackgroundColor Black -ForegroundColor yellow $Path = Read-Host "경로 입력 " $PathTest = Test-Path "$Path" if( $PathTest -lt "flase") { Write-Host "" Write-Host "경로확인 실패" -BackgroundColor Black -ForegroundColor Red Write-Host "해당 경로는 존재하지 않습니다." -BackgroundColor Black -ForegroundColor Red Write-Host "" } } Write-Host "경로 확인 성공" -BackgroundColor Black -ForegroundColor Red Write-Host "" Write-Host "현재 컴퓨터에 등록된 가상머신을 $Path\$env:computername-Hyper-V.rdg 파일로 저장합니다." -BackgroundColor Black -ForegroundColor Yellow Write-Host "작업중...." -BackgroundColor Black -ForegroundColor Red get-vm | select name,id | Export-csv -path $Path\$env:computername-Hyper-V.rdg -encoding utf8 $VMList = Get-Content $Path\$env:computername-Hyper-V.rdg $VMT=$VMList.split(",") $VMGet=$VMT.split("""") $VMCount = $VMGet.Count Write-Output " True$env:computername" > $Path\$env:computername-Hyper-V.rdg for($i=8;$i -lt $VMCount; $i+=6) { $VMID = $VMGet[$i+3] $VMDP = $VMGet[$i] Write-Output "$VMDP VirtualMachineConsoleConnect $VMIDlocalhost" >> $Path\$env:computername-Hyper-V.rdg } Write-Output "" >> $Path\$env:computername-Hyper-V.rdg $Encoding = Get-Content -Path $Path\$env:computername-Hyper-V.rdg $Encoding | Out-File -Encoding utf8 -FilePath $Path\$env:computername-Hyper-V.rdg Write-Host "모든 작업이 완료 되었습니다. $Path\$env:computername-Hyper-V.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 }