Editing scripts
From PowerGUI Wiki
Contents |
Syntax Highlighting
In the PowerGUI Script Editor, the following will be highlighted in specific colors to help identify those tokens more easily in a script:
- Cmdlet names (for example, Get-Command, Get-Help)
- alias names (such as gci, gcm)
- statement identifiers (for example, if, elseif, else, for, while, foreach)
- variables (for example, $ConfirmActionPreference)
- .NET Types
- comments
- quoted strings
Intellisense
The PowerGUI Script Editor supports Intellisense for
- cmdlets
- parameters
- WMI objects
- .NET objects
- variables
Intellisense is activated automatically when certain keys are pressed, such as when you press the dash (-) key after typing in Get.
Note: Intellisense can also be activated manually by pressing Ctrl+Space or through the Complete Word item in the Edit menu and button on the toolbar.
For WMI Intellisense, when using a WMI class that is not part of the default namespace, it is recommended that you enter the namespace parameter first and then the class parameter. That way, Intellisense shows you the list of classes available for the namespace you selected. For example:
Type Get-WmiObject –namespace <select your namespace> -class <select the class in that namespace>
Code Snippets
Snippets are small PowerShell code templates that include tooltips indicating what the various customizable parts of the snippet are used for.
PowerGUI supports insertion of PowerShell snippets in both the standalone Script Editor and the embedded editor in the PowerGUI admin console.
To insert a snippet
• Select Edit | Insert Snippet or press Ctrl+I.
Block Indent/Unindent
Within the script editor, you can indent or unindent a block of code by selecting the lines you want to change and then selecting the Edit | Advanced | Increase Indent or the Edit | Advanced | Decrease Indent menu option, accordingly.
You can also use the following shortcut keys:
• To indent the selected block of code, press Tab.
• To unindent the selected block of code, press Shift + Tab.
Block Comment/Uncomment
Within the script editor, you can comment out a block of code by selecting the lines you want to change and then selecting the Edit | Advanced | Comment Block or the Edit | Advanced | Uncomment Block menu option, accordingly.
You can also use the following shortcut keys:
• To comment out the selected block of code, press Ctrl + Shift + C.
• To uncomment the selected block of code, press Crtl + Shift + U.
Bookmarks
Within the script editor you can set bookmarks to mark the places in your script that you are working on. This facilitates making modifications in multiple places in large files when you cannot see the entire script on a page or two.
The bookmarks are located in the Tool bar and include
- Toogle Bookmark
- Previous Bookmark
- Next Bookmark
- Clear Bookmarks
To turn a bookmark on or off for a given line of script
• Place your cursor on the line and then click on the Toggle Bookmark button.
To navigate between bookmarks
• Click on the Previous Bookmark or Next Bookmark buttons.
To remove all bookmarks from your script
• Click on the Clear Bookmarks function.
Bookmarks are only active for the current file that you are working on during your current editing session. If you close your file, your bookmarks will be cleared.
