PowerShell allows the system to execute. ps1 files

Source: Internet
Author: User

The. ps1 file is a script file written by PowerShell. In Windows systems, it is not allowed to execute. ps1 files by default, so how can you allow the system to execute. ps1 files?

What is the. ps1 file?


This is the script text that PowerShell writes, you can write a PowerShell code in Notepad, then save it as "Xxx.ps1", and then double-click it to run when you want to use it later. This is a bit like a batch of ". bat" files and a bit like VBScript's ". vbs" file. These are script files for Windows.

How do I execute the ". PS1" file?


Then we will ask, then we will double-click it to run well, what else to say? Of course you have to say. We think very beautiful, double-click on the execution, but Windows system by default is not allowed to execute. ps1 file, so you have to look down.

Implementation of unsuccessful solutions


1. Save the contents of the PowerShell script to a. ps1 file that is a suffix.
2, double-click to execute this PS1 file is most likely unable to execute, Tip: Unable to load the file D:\PowerShell\test\myfirst1.ps1, because the script is forbidden in this system.
3, run Get-executionpolicy, if the result is restricted, that means to prohibit the execution of scripts.
4. Execute the following command to reduce the security of the system and allow script execution: Set-executionpolicy-executionpolicy unrestricted

About execution policies


Here is a executionpolicy, translation is the execution strategy. The default execution policy for Windows for PowerShell scripts is: No execution is allowed, that is, restricted. Change it to unrestricted nature can be carried out. But the best practise Microsoft has given is remotesigned, which is a bit higher than unrestricted and not a program to execute. As far as I can see, remotesigned is a PS1 script file that requires a remote download to be executed only if it is signed. As for our self-written script on this machine, it is no different, can be executed.

Modify execution policy requires permissions


It is also necessary to note that if it is on Win7, Win8, Windows 2008, Windows 2012 and other systems, and does not use the administrator account to execute this set-executionpolicy statement, will be an error, errors are as follows:
Set-executionpolicy: "Hkey_local_machine\software\microsoft\powershell\1\shellids\microsoft.powershell" to the registry key The access is denied.
At this time Hongo very puzzled, I use account although not administrator, but also administrators group, why do not have permission? Anyway, in the registry, find this key, then right-click on "Permissions" and then give the current login system's account with a "Full Control" permission (only "read-only" and "Full Control" two permissions, so choose "Full Control"). Then, re-execute set-executionpolicy-executionpolicy unrestricted, you can succeed!

Originally from: http://www.splaybow.com/post/powershellexecps1.html

PowerShell allows the system to execute. ps1 files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.