0

Need to make a script where the script will read the date from text file, then add the time in the variable. Use the variable in the script and make a scheduled task at remote computer.

$Reboot_Dt = Get-Content "C:\Reboot_Dt.txt"

Invoke-Command -ComputerName $SRV_Dest -Credential $cred -Scriptblock {
    $taskAction = New-ScheduledTaskAction -Execute "C:\Windows\system32\cmd.exe" -Argument "/k Shutdown /r /t 00'" 'Reboot by script Wrt. Windows Update
    $Trigger = New-ScheduledTaskTrigger -Once -At '$Reboot_Dt'
    $principal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
    Register-ScheduledTask 'WinUpd_Reboot' -Action $taskAction -Trigger $Trigger -Principal $principal
}

Error :-

Cannot process argument transformation on parameter 'At'. Cannot convert value "$Reboot_Dt" to type "System.DateTime". Error: "String was not recognized as a valid DateTime." + CategoryInfo : InvalidData: (:) [New-ScheduledTaskTrigger], ParameterBindin...mationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,New-ScheduledTaskTrigger + PSComputerName : xxxxxxxxx

Cannot validate argument on parameter 'Trigger'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. + CategoryInfo : InvalidData: (:) [Register-ScheduledTask], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Register-ScheduledTask + PSComputerName : xxxxxxxxx

2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Jan 12, 2024 at 18:14
  • Need to create a scheduled task at remote machine, purpose is to reboot the machine on a specific date (The date needs to be read from a text file). Via Get-content the date will be stored in a variable, which will be added by time. Afterwards this variable is used by New-ScheduledTaskTrigger -Once -At $Reboot_Dt Commented Jan 15, 2024 at 14:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.