Seeing as PowerShell is included by default in Windows 7, and also because you get the PowerShell icon on your quick launch bar by default, I try to use that over the de rigueur cmd.exe command interpreter that we have all had since the dawn of time. Although, without thinking, I still often run cmd.exe just through habit :-S. I am only just starting out with PowerShell and I doubt I will ever achieve any success with the scripting, but you have to try!
The PowerShell icon on the quick launch bar
Right from the start, I had problems running a script I had written. Upon launching it I would get the below error returned:
File C:\Users\daniel\Desktop\copy.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
At line:1 char:19
+ C:\Users\daniel\Desktop\copy.ps1 <<<<
No matter what I tried, I just could not override the security settings that PowerShell had by default. Frustration prevailed with me cursing the point of making a scripting environment and the blocking the execution of scripts for security reasons. After hunting around, it turns out that this is simply a configurable option, and the default setting out of the box is the most secure one (as it should be). Simply running the following commands will change the setting and thus allow you to execute your scripts.
To view your existing setting, run the command: Get-ExecutionPolicy
To allow the execution of your scripts, run the command: Set-ExecutionPolicy RemoteSigned
Setting it to RemoteSigned means that you can run all of the scripts you write yourself, but not those downloaded from the Internet. Alternatively, if you set the execution policy to AllSigned then all scripts, including those you write yourself, have to be signed by a trusted publisher if you want to execute them. Otherwise, you can set it to Unrestricted and then all scripts will run, regardless of where they come from and whether or not they’ve been signed. This last setting is not the recommended one as you can open yourself up to “a world of pain” (a great film).
And if you need help understanding the script signing, you can run the command: Get-Help About_Signing