Variables


PowerShell variables do not need to be declared up front. That's true in VBScript, except VBScript does give you the option of doing so, while PowerShell does not. However, explicit variable declaration is always optional in PowerShell.

Variables in PowerShell, like those in VBScript, can contain any type of data. In VBScript, this is done by making all variables the Variant type. In PowerShell, variables are the more generic Object type. Unlike in VBScript, you can tell PowerShell to force a variable to be of a certain type:

 [string]$var = "hello" 

This creates a new variable, $var, and forces it to be a string. Notice that all variable names being with $. Apart from that, PowerShell variable naming rules are similar to the rules in VBScript.

Variable naming in VBScript typically uses Hungarian notation, where a three-letter prefix such as obj, str, or int is used to denote the type of data the variable is intended to hold. PowerShell does not require this. In fact, when working with PowerShell this isn't considered a best practice. However, you're welcome to name your variables in this fashion if you're accustomed to doing so.



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