Solved

Automate powershell script when system boots

Posted on 2016-10-10
4
45 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Determining the an SCCM package name from the Package ID
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

623 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