<# 내용: 도메인내 컴퓨터를 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 " True$DomainName" > $Path\$DomainName.rdg for($i=0;$i -lt $CompCount; $i++) { $CompName = $CompGet.Name[$i] $CompIPv4 = $CompGet.IPv4Address[$i] $CompDesc = $CompGet.DistinguishedName[$i] Write-Output "$CompIPv4 [$CompName] $CompIPv4$CompDesc" >> $Path\$DomainName.rdg } Write-Output "" >> $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 }