Я пытаюсь развернуть запланированное задание для нескольких компьютеров в сети. Поэтому задача состоит в том, чтобы перезагрузить компьютеры после простоя в течение 1 часа +, когда компьютер заблокирован. Я не могу развернуть с помощью параметра -xml
. ошибка, которую я включил ниже.
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2020-05-02T14:35:05.1241005</Date>
<Author>ANT\user</Author>
<URI>\Reboot</URI>
</RegistrationInfo>
<Triggers>
<SessionStateChangeTrigger>
<Enabled>true</Enabled>
<StateChange>SessionLock</StateChange>
<Delay>PT1H</Delay>
</SessionStateChangeTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-1407069837-2091007605-538272213-32053677</UserId>
<LogonType>Password</LogonType>
<RunLevel>HighestPrivilege</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<Duration>PT1H</Duration>
<WaitTimeout>PT1H</WaitTimeout>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>true</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>false</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>true</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT72H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>%SystemRoot%\system32\shutdown.exe</Command>
<Arguments>-r -f -t 10</Arguments>
</Exec>
</Actions>
</Task>
$msg = "Enter the username and password that will run the task";
$credential = $Host.UI.PromptForCredential("Task username and password",$msg,"$env:userdomain\$env:username",$env:userdomain)
$username = $credential.UserName
$password = $credential.GetNetworkCredential().Password
Register-ScheduledTask -Xml (Get-Content "C:\Reboot.xml" | Out-String) -TaskName "Reboot" -RunLevel Highest -User $username -Password $password
Ошибка возврата по PS $
Register-ScheduledTask : Parameter set cannot be resolved using the specified named parameters.
At C:\Users\ermn\Desktop\P$.ps1:11 char:1
+ Register-ScheduledTask -Xml (Get-Content "C:\Reboot.xml" | Out-String ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Register-ScheduledTask], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Register-ScheduledTask