I was able to export all of my scheduled tasks using:
All i need to be able to do is import the scheduled task from the xml file
I have about 100 of these so any help would be appreciated.
$savefolder = "C:\stxml"
Get-ScheduledTask |
Foreach-Object { $_ | Export-ScheduledTask |
Out-File (Join-Path $savefolder "$($_.TaskName).xml") }
I am now trying to import them using powershell 5.1
I stated with:
Register-ScheduledTask -xml (Get-Content 'C:\stxml\test.xml' | Out-String) -TaskName "TEst Sch Task" -TaskPath "\" -User .\testuser -Force
Register-ScheduledTask : No mapping between account names and security IDs was done.
That lead me to:
$pre = new-scheduledtaskprincipal -userid testuser$ -logontype password; Register-ScheduledTask -xml (Get-Content 'C:\stxml\test.xml' | Out-String) -TaskName "TEst Sch Task" -TaskPath "\" -principal $pre
Register-ScheduledTask : Parameter set cannot be resolved using the specified named parameters.
I as able to boil this down to it not liking the -xml parameter.
My C:\stxml\test.xml file:
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2019-01-02T11:57:15.9628723</Date>
<Author>testuser</Author>
<Description>Does Stuff</Description>
<SecurityDescriptor></SecurityDescriptor>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2019-01-02T12:00:00</StartBoundary>
<Enabled>false</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
<CalendarTrigger>
<StartBoundary>2019-01-02T18:00:00</StartBoundary>
<Enabled>false</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>.\testuser</UserId>
<LogonType>Password</LogonType>
<RunLevel>LeastPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT10M</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>P3D</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions>
<Exec>
<Command>D:\some.vbs</Command>
</Exec>
</Actions>
</Task>