PrimalScript Tips


SAPIEN PrimalScript (version 4.1 and later) provides ample support specifically for PowerShell. Most of the timesaving features are automatic. This means you don't need to do anything to take advantage of things such as pop-up code completion menus called PrimalSense and syntax tooltips that remind you of a cmdlet's syntax.

However, some features require you to take some minor special steps. For example, as you learned in Chapter 5, all PowerShell variables are objects that have their own properties and methods. Normally, all variables are a generic object that doesn't offer any useful properties or methods. However, you can explicitly force variables into a certain type. If you do that within PrimalScript, it will display PrimalSense code-completion for the properties and methods associated with that type. For example, type this in PrimalScript:

 [string]$var = "Hello" $var. 

After typing the period after $var, you'll get a pop-up menu of the properties and methods for a String variable. This occurs because you've explicitly declared $var as a [string]; PrimalScript will remember that choice throughout your script. The trick is to assign a specific type to each variable the first time the variable is used. This ensures PrimalScript will "see" the type and treat the variable appropriately throughout your script.

A final tip is to learn to use PrimalScript's Snippets feature. A Snippet is basically a short section of code that you'll use over and over again. PrimalScript comes with a number of PowerShell Snippets built-in. To see the list, ensure that the Snippets Nexus is visible. If it is not, you can turn the Nexus panes on and off from the View menu. Once the Snippets Nexus is visible, expand the PowerShell folder. To use a Snippet, either drag it into the code editor, or type the Snippet name and press Ctrl+J. I prefer the second method since I like to keep my hands on the keyboard.

To make your own Snippet, highlight a section of code, right-click on it, and select Save as Snippet. Be sure to save the Snippet in with the other PowerShell Snippets. By saving code that you'll use over and over instead of retyping it, you'll be able to write scripts many times faster. You'll also introduce fewer bugs if your Snippets are thoroughly debugged before being saved.

PrimalScript provides a number of other useful features for working with PowerShell. Consult the free book PrimalScript® 4: TFM® for details (available at www.sapienpress.com) or check www.primalscript.com.



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