+4 votes
104 views
Windows: Run Powershell script

in Tips & Tricks by (552k points)
reopened | 104 views

1 Answer

+5 votes
Best answer

What is a Powershell script anyway?
Why can't a script like this just be started with a double click?
How can I still run my self-written script via the console?
How can I run my Powershell script by double-clicking it?

Have you written a script for Powershell and now you want to run it? We'll show you how to do it..

image image

With Powershell you can further optimize Windows. But it is not that easy to write scripts freely. That's why Microsoft prevents scripts from being executed just like that. Here are some tips for running scripts.

What is a Powershell script anyway?

A Powershell script is simply a text file that contains commands for the Powershell. Windows commands will be executed when this file is opened. Thus - with the appropriate know-how - simple applications or processes can be programmed in a file which Windows then executes. In this way, processes on the computer can be made much easier. Powershell scripts can be available as script files with the extension .ps1, script data files with the extension .psd1 or script module files with the extension .psm1.

Why can't a script like this just be started with a double click?

With Windows 10, Microsoft has replaced the old command window with Powershell. In the course of the switch, a few safety precautions were also taken. Powershell scripts cannot be opened with a double click, so that laypeople cannot simply open any text file with commands and thus endanger the stability of Windows. Because Powershell commands can intervene deeply in the system and, in the worst case, cause considerable damage..

How can I still run my self-written script via the console?

First of all, you should be sure that your script is working. So check again whether there are any errors in the text file.

  1. First, run PowerShell as an administrator. Get-ExecutionPolicy You can use the command to find out which policies are currently active. There are various security guidelines that Windows uses to decide whether a script is allowed to run. When in doubt, it should Restricted be. Restricted is the standard policy that prohibits the execution of any Powershell scripts.
  2. Then enter Set-ExecutionPolicy [Richtlinie] -force . Replace [policy] with one of the following directives:
  1. Unrestricted:
      This policy allows the execution of any Powershell scripts. It doesn't matter whether you wrote the script yourself or whether it came from the Internet or someone else.
    AllSigned:
      In this guideline, only scripts that have a digital certificate in the form of a digital signature are started. If not, Windows will ask if you can trust the publisher.
    RemoteSigned:
      All scripts that were created locally, i.e. that were written on this computer itself, are executed here. When you download a script from the Internet, it must have a digital signature in order for it to run.
  2. In order to be able to execute the script, open the corresponding folder / file path via the console in Powershell.
  3. Then enter the command \[Skriptname].ps1 . This will start your script.

How can I run my Powershell script by double-clicking it?

  1. Right click on your desktop and select " New Shortcut ".
  2. Enter the following as the location:
  1. %windir%\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -File "[Dateipfad]\[Skriptname].ps1"
  2. Then give the shortcut a unique name. If you now double-click on the link, the script that is saved with the corresponding script name in the corresponding file path will be executed automatically.

by (3.5m points)

Related questions

+4 votes
1 answer
+4 votes
1 answer
asked Jun 4, 2020 in Windows 10 by backtothefuture (552k points) | 1.3k views
+5 votes
1 answer
asked Jul 7, 2020 in Windows 10 by backtothefuture (552k points) | 253 views
Sponsored articles cost $40 per post. You can contact us via Feedback

Most popular questions within the last 30 days

10,659 questions
10,791 answers
510 comments
3 users