PowerShell03 – PowerShell script basics

Windows PowerShell script is a collection of Windows PowerShell Cmdlets/Commands. PowerShell scripts can be executed like batch files and it can also be configured to run as scheduled task! I will share few basics to start with PowerShell Scripting…
• PowerShell Scripts needs to be stored with .PS1 extension
• Comments: # is used as first character of a line to comment a line
• Comment multiple lines using
• How to execute PowerShell Script from a command line or Run
○ Powershell “C:\Folder\Fullpath\Script.ps1”
○ -noexit option to see the results

If you execute Powershell Script from Command prompt or Run, PowerShell will be closed after the script execution. Use -noexit option to see the output results, PowerShell windows will not be closed after the execution.
Powershell_noexit

• Execution Policy: This is most common problem for first time users of Powershell Script. By default only remotely signed scripts are allowed to execute, you need to change the execution policy settings.

○ Set-ExecutionPolicy Unrestricted can be used to change the policy and execute all script.
Powershell_ExecutionPolicy

* Learn more about execution policy at https://technet.microsoft.com/en-us/library/hh847748.aspx

Advertisements
This entry was posted in Learn_Powershell, Powershell and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s