Solved

Automate powershell script when system boots

Posted on 2016-10-10
4
20 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 9

Expert Comment

by:Muhammad Mulla
Comment Utility
1
 

Author Comment

by:Maniman man
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 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

8 Experts available now in Live!

Get 1:1 Help Now