Files
RDP-login-monitor/Install-DomainMonitors.ps1
T
PTah 872df98a2c fix: Exchange monitor encoding for PS 5.1 (v1.6.3)
ASCII runtime strings in Exchange-MailSecurity and Notify-Common avoid parser errors when scripts are copied without UTF-8 BOM. Deploy copies .ps1 to ProgramData with UTF-8 BOM via Copy-ScriptFileWithUtf8Bom.
2026-05-22 14:57:35 +10:00

52 lines
1.6 KiB
PowerShell

<#
.SYNOPSIS
Register scheduled tasks for domain monitors (Exchange; AD later).
.PARAMETER Target
Exchange - Exchange-MailSecurity.ps1; Ad - reserved.
#>
[CmdletBinding()]
param(
[ValidateSet('Exchange', 'Ad')]
[Parameter(Mandatory = $true)]
[string]$Target
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$InstallRoot = [System.IO.Path]::GetFullPath("$env:ProgramData\RDP-login-monitor")
$PsExe = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
function Test-RunningElevated {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
if ($null -ne $id.User -and $id.User.Value -eq 'S-1-5-18') { return $true }
$p = New-Object Security.Principal.WindowsPrincipal($id)
return $p.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (-not (Test-RunningElevated)) {
throw 'Run Install-DomainMonitors.ps1 as Administrator.'
}
switch ($Target) {
'Exchange' {
$scriptPath = Join-Path $InstallRoot 'Exchange-MailSecurity.ps1'
if (-not (Test-Path -LiteralPath $scriptPath)) {
throw "Not found: $scriptPath"
}
$notifyPath = Join-Path $InstallRoot 'Notify-Common.ps1'
if (-not (Test-Path -LiteralPath $notifyPath)) {
throw "Not found: $notifyPath"
}
& $PsExe -NoProfile -ExecutionPolicy Bypass -File $scriptPath -InstallTasks
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Write-Host 'Exchange: scheduled tasks registered.'
}
'Ad' {
Write-Host 'AD-SecurityMonitor.ps1 is not implemented yet. Use -Target Exchange.'
exit 1
}
}
exit 0