-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsg.ekb.ru
27 lines (21 loc) · 1.16 KB
/
tsg.ekb.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
scp -qr /etc/ssl/uxm tsg.ekb.ru:/inetpub/x509
cat <<"EOF" | ssh tsg.ekb.ru powershell -c -
# Import PFX
$crt = Import-PfxCertificate -FilePath "C:\inetpub\x509\uxm\ekb-ru.pfx" -CertStoreLocation Cert:\LocalMachine\My
# Update IIS
Get-WebBinding | Where-Object { $_.certificateHash } | ForEach-Object { $_.AddSslCertificate($crt.Thumbprint, 'My') }
# Update TSG / RDS
$cmd = "Set-RDCertificate -Role RDGateway -Thumbprint $($crt.Thumbprint) -Force"
$restart = "Restart-Service TSGateway"
$cmd = "$cmd ; $restart"
# psexec -accepteula -nobanner -s powershell -c $cmd
# restart service: TSGateway
exit
# Run as System service via Scheduled Task
$Action = New-ScheduledTaskAction -Execute "powershell" -Argument "-c '$cmd'"
$Trigger = Get-CimClass -ClassName 'MSFT_TaskRegistrationTrigger' -Namespace 'Root/Microsoft/Windows/TaskScheduler'
$Settings = New-ScheduledTaskSettingsSet -DeleteExpiredTaskAfter 00:01:00
$Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings
$Task.Triggers[0].EndBoundary = (Get-Date).AddMinutes(1).ToString('s')
Register-ScheduledTask -TaskName "RDGateway.x509" -TaskPath uxm -InputObject $Task -User "System" -Force | Out-Null
EOF