-
Notifications
You must be signed in to change notification settings - Fork 4
/
set-scheduledTaskToInstallODriveToOnedriveAtLogon.ps1
33 lines (27 loc) · 6.91 KB
/
set-scheduledTaskToInstallODriveToOnedriveAtLogon.ps1
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
28
29
30
31
32
33
<#
.SYNOPSIS
Force-creates a scheduled task that fires upon login of any user.
It then tries to discover the Onedrive folder of the logged in user.
If none is found, it will keep trying for the duration of the session with a slowly increasing interval.
If Onedrive is discovered, a drivemapping to it will be (re)created using the driveletter O
To decode / recode base64, use https://www.base64encode.org/ and select UTF-16LE as encoding type.
.NOTES
author: Jos Lieben / jos@lieben.nu
copyright: https://www.lieben.nu/liebensraum/commercial-use/ (Commercial (re)use not allowed without prior written consent by the author, otherwise free to use/modify as long as header are kept intact)
site: https://www.lieben.nu
Created: 04/07/2023
#>
$taskName = "LC_INSTALLODRIVE"
$SchedService = New-Object –comobject 'Schedule.Service'
$SchedService.Connect()
$Task = $SchedService.NewTask(0)
$Task.RegistrationInfo.Description = $taskName
$Task.Settings.Enabled = $true
$Task.Settings.AllowDemandStart = $true
$trigger = $task.triggers.Create(9)
$trigger.Enabled = $true
$action = $Task.Actions.Create(0)
$action.Path = 'PowerShell.exe'
$action.Arguments = '-WindowStyle hidden -ex bypass -EncodedCommand PAAjAA0ACgAgACAAIAAgAC4AUwBZAE4ATwBQAFMASQBTAA0ACgAgACAAIAAgAFQAcgBpAGUAcwAgAHQAbwAgAGQAaQBzAGMAbwB2AGUAcgAgAHQAaABlACAATwBuAGUAZAByAGkAdgBlACAAZgBvAGwAZABlAHIAIABvAGYAIAB0AGgAZQAgAGwAbwBnAGcAZQBkACAAaQBuACAAdQBzAGUAcgAuAA0ACgAgACAAIAAgAEkAZgAgAG4AbwBuAGUAIABpAHMAIABmAG8AdQBuAGQALAAgAGkAdAAgAHcAaQBsAGwAIABrAGUAZQBwACAAdAByAHkAaQBuAGcAIABmAG8AcgAgAH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AgACAAIAAgAH0AYwBhAHQAYwBoAHsADQAKACAAIAAgACAAIAAgACAAIAAgACAAIAAgAFcAcgBpAHQAZQAtAEwAbwBnACAAIgBGAGEAaQBsAGUAZAAgAHQAbwAgAG0AYQBwACAAJAB0AGEAcgBnAGUAdABMAG8AYwBhAHQAaQBvAG4AIAB0AG8AIABPADoAIABiAGUAYwBhAHUAcwBlACAAbwBmACAAJABfACIADQAKACAAIAAgACAAIAAgACAAIAB9AA0ACgAgACAAIAAgAH0ADQAKACAAIAAgACAADQAKACAAIAAgACAAVwByAGkAdABlAC0ATABvAGcAIAAiAEQAaQBkACAAbgBvAHQAIABkAGUAdABlAGMAdAAgAHUAcwBlAHIAIABPAG4AZQBkAHIAaQB2AGUAIABmAG8AbABkAGUAcgAgAHUAbgBkAGUAcgAgACQAKAAkAGUAbgB2ADoAdQBzAGUAcgBwAHIAbwBmAGkAbABlACkALAAgAHQAcgB5AGkAbgBnACAAYQBnAGEAaQBuACAAaQBuACAAJAByAGUAdAByAHkAQQBmAHQAZQByAFMAZQBjAG8AbgBkAHMAIgANAAoAIAAgACAAIABTAHQAYQByAHQALQBTAGwAZQBlAHAAIAAtAFMAZQBjAG8AbgBkAHMAIAAkAHIAZQB0AHIAeQBBAGYAdABlAHIAUwBlAGMAbwBuAGQAcwANAAoAIAAgACAAIAAkAHIAZQB0AHIAeQBBAGYAdABlAHIAUwBlAGMAbwBuAGQAcwAgACsAPQAgADEAIAAjAGkAbgBjAHIAZQBhAHMAZQAgAHcAYQBpAHQAIAB0AGkAbQBlACAAYgB5ACAAbwBuAGUAIABzAGUAYwBvAG4AZAAgAGUAYQBjAGgAIAB0AGkAbQBlAA0ACgB9AA=='
$taskFolder = $SchedService.GetFolder("\")
$taskFolder.RegisterTaskDefinition($taskName, $Task , 6, 'Users', $null, 4)