alanlam123
asked on
Scripting
Hi expert
How fo write a schedule task for a powershell restart script that able to automate without putting password during restart?
Thanks
Alan Lam
How fo write a schedule task for a powershell restart script that able to automate without putting password during restart?
Thanks
Alan Lam
Why do you need a script? Just schedule shutdown.exe.
have you seen this article: https://www.lifewire.com/how-do-i-auto-login-to-windows-2626066
for "permanent" scripts am I using this piece of code to register scheduled task for it
$a=$null
$sensitivity=15 #run every 15 minutes
$scriptfile="c:\tools\scripts\myscript.ps1" #path to script
if ((Get-ScheduledJob PSScript -ErrorAction SilentlyContinue).Id) {
$a=read-Host -Prompt "PSScript job is already registerd on this system, do you want to continue? (enter y or Y for reinstall)"
if ($a.ToUpper() -eq 'Y'){Unregister-ScheduledJob PSScript} else {exit}
}
$taskuser=Get-Credential -message 'Provide username and passowrd for PSScript job:'
$options = New-ScheduledJobOption -RunElevated -ContinueIfGoingOnBattery -StartIfOnBattery -MultipleInstancePolicy StopExisting
$t=New-JobTrigger -Once -at ((Get-Date)+(New-TimeSpan -Minutes 3)) -RepetitionInterval (New-TimeSpan -Minutes $sensitivity) -RepetitionDuration ([TimeSpan]::MaxValue)
Register-ScheduledJob -Name PSScirpt -FilePath $scriptfile -Credential $taskuser -ArgumentList Monitor -Trigger $t -ScheduledJobOption $options
write-host "Scheduled job re-/registered."
ASKER
Hi all
Thanks for the reply.
Sorry if I not clear currently I using a powershell script to restart , each restart require to manually enter the password for each application.
In theory I like to automate the powershell script by schedule task without enter password for each application.
Not sure how to achieve this , I aware that powershell script don't work correctly with schedule task. Correct me if I wrong.
Thanks for the reply.
Sorry if I not clear currently I using a powershell script to restart , each restart require to manually enter the password for each application.
In theory I like to automate the powershell script by schedule task without enter password for each application.
Not sure how to achieve this , I aware that powershell script don't work correctly with schedule task. Correct me if I wrong.
I have absolutely no problems using powershell from a scheduled task.
but you want to restart applications and providing password for those applications? Just be sure that those applications need to support that.
but you want to restart applications and providing password for those applications? Just be sure that those applications need to support that.
ASKER
How to achieve this for the automation.
Sorry, but what does
mean? Especially what do you mean by "enter password for each application"? Where does this connect to scheduled tasks or PowerShell scripts?
If you're talking about the (user) account used by Scheduled Tasks: Maybe you're looking for managed service accounts.
In theory I like to automate the powershell script by schedule task without enter password for each application.
mean? Especially what do you mean by "enter password for each application"? Where does this connect to scheduled tasks or PowerShell scripts?
If you're talking about the (user) account used by Scheduled Tasks: Maybe you're looking for managed service accounts.
ASKER
L
In the restart powershell script were triggering each application to restart for the following;sequence;
Once restart;
Application A need to input password
Application B need to input password
Application C need to input password
Example application A, once restart it required me to input the password for each.
Is this possible to achieve by writing a powershell script to hard coded rhe password for each application.
That mean no longer need to input the password.
Once done, I like to run the powershell script in the schedule task.
Thanks
In the restart powershell script were triggering each application to restart for the following;sequence;
Once restart;
Application A need to input password
Application B need to input password
Application C need to input password
Example application A, once restart it required me to input the password for each.
Is this possible to achieve by writing a powershell script to hard coded rhe password for each application.
That mean no longer need to input the password.
Once done, I like to run the powershell script in the schedule task.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
author lost interest?