Solved

Automate powershell script when system boots

Posted on 2016-10-10
4
27 Views
Last Modified: 2016-10-15
Hello Everyone,

I have the following powershell script:
(Get-Content C:/sample.txt -TotalCount 1) | Set-Content C:\sample.txt
I would like the above script to execute when system boot.

Can someone please advise the best option to do so?
Thank you
Manu
0
Comment
Question by:Maniman man
  • 3
4 Comments
 
LVL 10

Expert Comment

by:Muhammad Mulla
ID: 41836639
1
 

Author Comment

by:Maniman man
ID: 41836650
Hey thank you,

I have tried that unfortunately it did not work.
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1 PowerShell C:/sample.ps1>> "%TEMP%\StartupLog.txt" 2>&1

But did not work, maybe am missing something.
0
 

Accepted Solution

by:
Maniman man earned 0 total points
ID: 41836760
Best solution to solve the situation: -create a .cmd file to execute automatically your script at system boot, with following script: PowerShell -Command "Set-ExecutionPolicy Unrestricted" | powershell.exe -noexit C:\cldscripts\sample.ps1

Copy and save your .cmd file in the following path: C:\Users\youruser\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup Reboot your system and the scrip will automatically run.

Another way I found, is to use the grouop local editor: Run the gpedit.msc and enter. In the left pane tree choose windows settings under Computer configuration, double click on the feature "Scripts (Startup/Shutdown)" and add your script to run automatically at system boot or shutdown.

Best Regards
Manu
0
 

Author Closing Comment

by:Maniman man
ID: 41844872
Looking at the previous answer, plus researching on other forums, I have found the best solution to answer my own question. I have just tested it in prod environment with sucess results.
Best Regards
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
This article will help you understand what HashTables are and how to use them in PowerShell.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now