Programming‎ > ‎

PowerShell

I started managing TFS and thus learning about Microsoft PowerShell.

Update: 10/14/2015

Index

How can I avoid Execution Error for a PowerShell script?

Trying to run a PowerShell script will give me the Execution Policy error. In order to avoid this everytime, you create your profile in the following way:

   
  Test-Path $profile 
  should return "False".  Then do   
  New-Item -path $profile -type file -force 
  will create C:\Users\(username)\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1. 
  Now add the following to this file   
  Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy Bypass   
      Get-Executionpolicy   Echo "Execution Policy Set"
  
Note that only Bypass option can be accepted in the profile. Other options like "Unrestricted" will cause error.

Top


How can I associate .ps1 to PowerShell or PowerShell ISE?

  
  1. Control Panel → Appearance and Personalization → Folder Options   
  2. Uncheck Hide extensions for known file type.  
  3. Now pick the profile you created above in Windows Explorer.  
     Right Click → Open With → Browse.  
  4. Go to C:\Windows\System32\WindowsPowerShell\v1.0\ and select either powershell.exe 
     or powershell_ise.exe. Make sure that you check "Always use the selected program to 
	 open this kind of file".
  

If you picked powershell.exe, then clicking on *.ps1 will open PowerShell, run the script, and close.If you picked powershell_ise.exe, then clicking on *.ps1 will open the PowerShell ISE and put the script in the file pane. If you do both, then right-clicking on the *.ps1 will have options of either powershell or powershell_ise.

Top