Scripts


So far, we looked at ways to run cmdlets directly and view their output. PowerShell scripts are designed to string several cmdlets together to automate more complex tasks. PowerShell scripts must have the filename extension .PS1; to run a script, simply type its name without the extension. PowerShell will look in the environment Path variable or any files with the .PS1 extension to find your script. If your script takes input arguments, then type them after the script name:

 . Myscript arg1 arg2 

Did you notice the period at the beginning of the line? This period tells PowerShell to execute the script in the current scope, which we'll discuss in a bit. Scripts use their own language, which is similar to both VBScript and C#. Most of the remainder of this book will be spent discussing this scripting language.

How Can it Tell?

How can PowerShell tell when you're typing a script name, cmdlet name, or alias? When you type any name, PowerShell first looks for an alias, then a function, then a cmdlet, then a script, and then an external executable.

Why did Microsoft choose to use a new language rather than using something that already existed like VBScript? A few reasons come to mind. First, PowerShell is built on .NET, which is the scripting language needed to leverage .NET's features and capabilities, which VBScript certainly can't do. In fact, no scripting language existed that could really utilize .NET. In addition, a new language could also be more consistent than languages like KiXtart, which evolved over time and are a bit of a mishmash. Microsoft decided to go with a language that was essentially a subset of the C# .NET language, which allows an easier "upscale" from PowerShell to the full C# language should you ever want to make that leap.



Windows PowerShell. TFM
Internet Forensics
ISBN: 982131445
EAN: 2147483647
Year: 2004
Pages: 289

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net