1

I'm working on an installation script of certain software I am developing. Installation of the software on a remote server requires a certain startup script to run on each boot.

I'm writing a powershell script so I'm looking for a way to create a start up script from powershell I have the batchfile ready to execute I just need to run it on each boot of the remote server

I couldn't find any resources on Google therefore I am asking here if anyone could achieve such a result

1

3 Answers 3

3

This is one of the way you can create a startup script using powershell. This will create a startup script. Everytime you restart your machine, the script will execute

$TaskAction1 = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-ExecutionPolicy Bypass -File C:\scripts\Config.ps1"
$TaskTrigger = New-ScheduledTaskTrigger -AtStartup
$TaskPrincipal = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -LogonType ServiceAccount -RunLevel Highest
Register-ScheduledTask -Action $TaskAction1 -Trigger $TaskTrigger -Principal $TaskPrincipal -TaskName "Config" -Description "Config Script"
Sign up to request clarification or add additional context in comments.

Comments

-1

You can start a command procedure from PowerShell with the following code. Replace the path and file with your own information.

C:Pathfile.bat

Once you’ve called your batch file, you can customize it to the task at hand. For example…

If you want to capture the output of the .bat file, you can use:

$out = C:Pathfile.bat

If you want to start a process with your .bat file, you can use the PowerShell start-process cmdlet:

start-process C:Pathfile.bat

And, if you if you want to control cmd.exe, you can use this:

start-process "cmd.exe" "/c C:Pathfile.bat"

The start-process cmdlet is a standard PowerShell cmdlet, so anyone can use it. JAMS users leverage it regularly and combine it with JAMS specific cmdlets in our PowerShell snap-in to add intelligent automation to batch files.

Place it in this path:

C:\Users\<user_name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\startup.cmd

1 Comment

I'm looking for a solution that does not work per user, I want the startup script to run for any user that logs on not a specific one.
-1

To run your script on each boot of the remote server, do following settings on remote server.

  1. open task scheduler (Win+R and enter command "%windir%\system32\taskschd.msc /s"
  2. Action --> Create Task
  3. Select required options in 'General' tab
  4. Click on 'Triggers'-->New --> Begin the task: select 'At Startup' from dropdown list.
  5. Click on 'Actions' --> New --> Action: 'Start a Program' --> Settings: path to your script.

To configure point number 5 you can take help on google.

Comments

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.