#======================================================================================
$TaskName = 'Export-WindowsDriverOnline'
$TaskPath = '\Corporate\Drivers'
Exports third party drivers to $env:SystemDrive\ExportedDrivers
Transcripts are stored in $env:SystemRoot\Logs\Drivers
Runs as SYSTEM and does not display any progress or results
PowerShell Encoded Script
#======================================================================================
$TaskName = 'Export-WindowsDriverOnline'
#======================================================================================
#======================================================================================
$TaskLogs = "$env:SystemRoot\Logs\Drivers"
if (!(Test-Path $TaskLogs)) {New-Item $TaskLogs -ItemType Directory -Force | Out-Null}
$TaskLogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$TaskName.log"
Start-Transcript -Path (Join-Path $TaskLogs $TaskLogName)
#======================================================================================
#======================================================================================
#if (!(Test-Path $TaskLogs)) {New-Item $TaskLogs -ItemType Directory -Force | Out-Null}
Export-WindowsDriver -Online -Destination $env:SystemDrive\ExportedDrivers
#======================================================================================
#======================================================================================
#======================================================================================
$EncodedCommand = [System.Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($TaskScript))
#======================================================================================
Execute = 'powershell.exe'
Argument = "-ExecutionPolicy ByPass -EncodedCommand $EncodedCommand"
AllowStartIfOnBatteries = $true
MultipleInstances = 'Parallel'
ExecutionTimeLimit = (New-TimeSpan -Minutes 60)
Action = New-ScheduledTaskAction @Action
Principal = New-ScheduledTaskPrincipal @Principal
Settings = New-ScheduledTaskSettingsSet @Settings
Description = $Description
#======================================================================================
New-ScheduledTask @ScheduledTask | Register-ScheduledTask -TaskName $TaskName -TaskPath $TaskPath -Force
#======================================================================================
# Apply Authenticated User Permissions
$Scheduler = New-Object -ComObject "Schedule.Service"
$GetTask = $Scheduler.GetFolder($TaskPath).GetTask($TaskName)
$GetSecurityDescriptor = $GetTask.GetSecurityDescriptor(0xF)
if ($GetSecurityDescriptor -notmatch 'A;;0x1200a9;;;AU') {
$GetSecurityDescriptor = $GetSecurityDescriptor + '(A;;GRGX;;;AU)'
$GetTask.SetSecurityDescriptor($GetSecurityDescriptor, 0)