You can run powershell scripts in two ways.
Before running any script file, you must first set an appropriate execution policy.
Powershell scripts, like Windows cmd, and like MS-DOS batch processing, files need to be saved as. PS1 extensions, such as myscript. PS1
The most common method to run a script is to call it:
PS c: \> & "C: \ belfry \ my first script. PS1"
Note: The "&" operator allows you to call a command, script, or function. For example:
PS c: \> & "C: \ Program Files \ mycommand.exe"
Ps c :\> $ runmyprog = "C: \ Program Files \ mycommand.exe"
PS c: \> & $ runmyprog
PS c: \> $ myping = Get-command-commandtype application Ping
PS c: \> & $ myping
If the path does not contain any spaces, you can ignore the quotation marks and the '&' operator.
PS c: \> C: \ belfry \ myscript. PS1
If the script is in the current path, you must use the ". \" symbol to tell powershell that the script is in the current path.
PS c: \>. \ myscript. PS1
Dot Sourcing
==================================
When the preceding syntax is used to execute the script, the variables and functions defined in the script disappear after the script is run.
However, if you use dot sourcing to run the script, all variables and functions defined in the script will still exist after the script is run.
Run the dot-sourcing script.
PS c: \>. "C: \ belfry \ my first script. PS1"
Run the dot-sourcing script in the current path.
PS c: \> .. \ myscript. PS1"
References
==================================
Run a powershell script
Http://ss64.com/ps/syntax-run.html
Using the set-executionpolicy cmdlet
Http://technet.microsoft.com/en-us/library/ee176961.aspx