-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathports-task.ps1
More file actions
26 lines (19 loc) · 760 Bytes
/
Copy pathports-task.ps1
File metadata and controls
26 lines (19 loc) · 760 Bytes
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
$erroractionpreference = 'stop'
$taskname = 'Forward Server Ports'
$trigger = new-scheduledtasktrigger -atlogon
# If the $profile maps an alias for ssh, get-command returns that alias, whose
# source is the module it came from and not the path a task action needs.
$ssh = get-command ssh
while ($ssh.commandtype -eq 'Alias') { $ssh = $ssh.resolvedcommand }
$action = new-scheduledtaskaction `
-execute $ssh.source `
-argument '-NT server-ports'
$principal = new-scheduledtaskprincipal `
-userid $env:username `
-logontype s4u
register-scheduledtask -force `
-taskname $taskname `
-trigger $trigger -action $action `
-principal $principal `
-ea stop | out-null
"Task '$taskname' successfully registered to run at logon."