内容
- RD WEBに必要なIIS、証明書、リモートアプリを一括設置する
- サーバーにドメイン管理者でログイン
- PS_ISEをドメイン管理者権限で実行
PowerShell
(---)
[int]$IsProduct = 1 //本番・開発区分
$ADName = "ad-product" //Active Directiveサーバ名
//サーバはAWS上にある(参考まで)
try {
#0=aws-dev
$pkey = Invoke-RestMethod -Uri "http://169.254.169.254/latest/meta-data/public-keys" -TimeoutSec 3
if ($pkey.Contains("aws-dev")) {
$IsProduct = 0
$ADName = "ad-dev"
}
}
catch {
Write-Host `n "サーバが見つかりません"
}
Import-Module RemoteDesktop
Import-Module RemoteDesktopServices
Import-Module "\\${ADName}\share\ps1\common.psm1"
$sys = Get-WmiObject Win32_ComputerSystem
[string]$serverFullname = $sys.Name + "." + $sys.Domain
# ADにあるコンピューターオブジェクトを規定OUに移動(参考まで)コンピューターからADにあるPowerShellリモート実行
function Move-Computer() {
[int]$kid = Get-KokyakuId
[string]$sid = Get-ServerId
$path = "\\${ADName}\share\ps1\v10\012_admin_move_computer.ps1"
Invoke-Command -ComputerName $ADName -FilePath $path -ArgumentList $kid, $sid
}
# パス込みなので使用後削除(参考まで)
function Remove-FirstPs1() {
$path = "C:\workspace\ps1\021_first_host.ps1"
if (Test-Path $path) {
Remove-Item $path
}
}
# 証明書インポート
function Import-Cert() {
write-host `n "証明書インポート" -foregroundcolor White -backgroundcolor Blue
$certPath = "\\${ADName}\share\ps1\awscloud.pfx"
certutil -p {証明書パスワード} -importpfx $certPath
}
# アクセス権限:グループ
function New-App() {
[int]$kid = Get-KokyakuId
$sid = Get-ServerId
$gid = Get-GroupId
$collection = "{コレクション名}"
$liceseServer = "{ライセンスサーバ}"
#
New-SessionDeployment -ConnectionBroker $serverFullname -WebAccessServer $serverFullname -SessionHost $serverFullname
#コレクション作成
New-RDSessionCollection -CollectionName $collection -SessionHost @($serverFullname) -CollectionDescription "{コレクションサービス名}" -ConnectionBroker $serverFullname
Set-RDSessionCollectionConfiguration -UserGroup "${gid}" -CollectionName $collection -ConnectionBroker $serverFullname -AuthenticateUsingNLA $false
#
Write-Host `n "証明書登録" -foregroundcolor White -backgroundcolor Blue
$password = ConvertTo-SecureString -String "{証明書パスワード}" -AsPlainText -Force
Set-RDCertificate -Role RDWebAccess -ImportPath "\\${ADName}\share\ps1\awscloud.pfx" -Password $password -ConnectionBroker $serverFullname -Force
Set-RDCertificate -Role RDRedirector -ImportPath "\\${ADName}\share\ps1\awscloud.pfx" -Password $password -ConnectionBroker $serverFullname -Force
Set-RDCertificate -Role RDPublishing -ImportPath "\\${ADName}\share\ps1\awscloud.pfx" -Password $password -ConnectionBroker $serverFullname -Force
#RemoteApp追加
if ($IsProduct -eq 1) {
#Office追加(参考まで)
$officeKid = "office_${gid}"
$excelPath = "C:\Program Files\Microsoft Office\Office15\EXCEL.EXE"
New-RDRemoteApp -CollectionName $collection -DisplayName "Excel" -FilePath $excelPath -UserGroup $officeKid
Write-Host `n "ライセンスサーバー指定" -foregroundcolor White -backgroundcolor Blue
set-rdlicenseconfiguration -LicenseServer $liceseServer -Mode PerUser -Force
}
$appPath = "C:\RemoteApp\Start.exe"
$appGrp = "grp_${gid}"
New-RDRemoteApp -CollectionName $collection -DisplayName "{アプリ表示名}" -FilePath $appPath -UserGroup $appGrp
#RDSession portをディフォルトから変更した場合
Write-Host `n "RDSession Port変更" -foregroundcolor White -backgroundcolor Blue
Set-RDSessionCollectionConfiguration -CollectionName {コレクション名} -CustomRdpProperty "server port:i:43389
full address:s:app-${kid}-${sid}.awscloud.com"
}
function Main() {
#
Move-Computer
#
Remove-FirstPs1
#
Import-Cert
#
New-App
}
Main
メモ
- DSCの方が好ましいが、PowerShell触って間もない時に書いたもんでご参考までに。