Hi expert

How fo write a schedule task for a powershell restart script that able to automate without putting password during restart?

Alan Lam
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Why do you need a script? Just schedule shutdown.exe.
Éric MoreauSenior .Net ConsultantCommented:
rastoiWindows DTS expertCommented:
for "permanent" scripts am I using this piece of code to register scheduled task for it

$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."

Open in new window

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

alanlam123Author Commented:
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.
Éric MoreauSenior .Net ConsultantCommented:
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.
alanlam123Author Commented:
How to achieve this for the automation.
ste5anSenior DeveloperCommented:
Sorry, but what does

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.
alanlam123Author Commented:

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.

rastoiWindows DTS expertCommented:
there is many applications where you can pass password like parameter in starting command (ofter hidden parameter).
You have to verify if this is not the case.
Otherwise you can use some tricks to enter passwords, i.e. like my another script " here on EE.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rastoiWindows DTS expertCommented:
author lost interest?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.