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 the system allow the execution of. ps1 files?
What is a ". PS1" file?
This is the script text written by PowerShell, you can write a section of PowerShell code in Notepad, then save it as "Xxx.ps1", after you want to use it, double-click can run. This is a bit like a batch of ". bat" files, and a bit like VBScript's ". vbs" file. These are all script files for Windows.
How do I execute the ". PS1" file?
Next people will ask, then we double-click it to run well, what else to say? Of course I have to say. We thought it was pretty, but the Windows system is not allowed to execute the. ps1 file by default, so you have to look down.
Implementation of unsuccessful solutions
1. Save the PowerShell script contents to a file with a. ps1 suffix.
2, double-click to execute this PS1 file is likely to be unable to execute, prompting: file D:\PowerShell\test\myfirst1.ps1 cannot be loaded because scripts are not allowed in this system.
3, run Get-executionpolicy, if the result is restricted, that means the execution of scripts is prohibited.
4, execute the following command, reduce the security of the system, allow the execution of scripts: Set-executionpolicy-executionpolicy Unrestricted
About implementing policies
Here is a executionpolicy, translation is to implement the strategy. The default execution strategy for Windows for PowerShell scripts is: Do not allow execution, that is, restricted. Change it to unrestricted and it will be done. But the best practise that Microsoft has given is remotesigned, which is a bit higher than unrestricted, not a program that can be executed. As far as I can see, remotesigned is a PS1 script file that requires a remote download to be signed to execute. As for the scripting that we write on this machine, that's no different, it can be done.
Permissions are required to modify the execution policy
Also need to note that if it is on the Win7, Win8, Windows 2008, Windows 2012 and other systems, and do not use the administrator account to execute the Set-executionpolicy statement, will be an error, as follows:
Set-executionpolicy: "Hkey_local_machine\software\microsoft\powershell\1\shellids\microsoft.powershell" for registry entries Access is denied.
This time the small set very puzzled, I use the account although not the administrator, but also is the Administrators group, why does not have the authority? Whatever it is, in the registry, locate the key, then right-click to select "Permissions" and add a "Full Control" permission to the current login system (only "read Only" and "Full Control" two permissions, so select "Full Control"). Then, to perform set-executionpolicy-executionpolicy unrestricted again, you can succeed!