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