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
alanlam123Asked:
Who is Participating?
 
rastoiConnect With a Mentor Windows 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.
0
 
ste5anSenior DeveloperCommented:
Why do you need a script? Just schedule shutdown.exe.
1
 
Éric MoreauSenior .Net ConsultantCommented:
0
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
rastoiWindows DTS expertCommented:
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."

Open in new window

0
 
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.
0
 
É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.
0
 
alanlam123Author Commented:
How to achieve this for the automation.
0
 
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.
0
 
alanlam123Author Commented:
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
0
 
rastoiWindows DTS expertCommented:
author lost interest?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.