How To Write Basic Scripts In Windows Powershell

Thumb

How To Write Basic Scripts In Windows Powershell

Windows PowerShell is an especially designed Windows command-line (Much like DOS) shell for system administrators. PowerShell provides an interactive prompt environment that allows scripting and can be used independently or in combination with other programs. Individuals doing their receiving their ITSM training will be trained in how to handle PowerShell commands and setting it up for administrative purposes in an organization.

Creating A Script File In Powershell

On the toolbar, click the option New, or you can do the same in the File menu. The newly created file appears in a tab under the powershell tab that you had selected. The user should keep in mind that the PowerShell tabs are visible once there are multiple created, otherwise you will just see the main window. As a default file name, (.ps1) type script is created, but the name and extension can be changed according to preference. Different script files can be created in a single PowerShell tab.

This article explains the very basics of writing scripts in PowerShell, for understanding PowerShell and its capabilities fully, individuals can seek out Windows PowerShell certification programs.

Opening An Existing Script

If you want to continue working on a previously saved script or load a template that you would like to work with, go to the toolbar and click Open, or just go on the File menu once again and click Open there. The file you choose will be opened in a new tab.

Closing A Script Tab

Fairly quite simple, choose the cript tab that you want to close and then do either of the following:

  1. Press the (x) icon on the tab
  2. Go to File menu and click close

Like most programs, if you have altered the file since it was last accessed, a prompt will open to remind you to save before closing.

How To Display A File Path

Go to the file tab and point to the file name. After a while, the full patj to the script file appears in tooltip.

Running A Script

Go to the toolbar and click Run Script, or on the File menu click on Run.

Running A Portion Of A Script

  1. In the script pane, select the portion of the script you want to run.
  2. Go to the File menu, and then click Run Selection, or on the toolbar, click Run Selection.

Stopping A Script

Go to the toolbar and click on Stop Operation, or click on the File menu and click Stop Operation. CTRL+C is also an alternative way of stopping a script, unless something is selected, in which case the command will copy the selected part of the script.

Writing And Editing Text In Script Pane

You can follow these steps to edit text in the Script Pane. The script Pane allows you to cut, copy, paste, replace and find text. An undo and redo option is also given for the user’s ease. The shortcuts used here are the same as other windows applications.

Entering Text In The Script Pane

  1. Take the cursor to the Script Pane by clicking on the Script Pane, or by selecting Go to Script Pane in the View menu.
  2. Create a script. You can use syntax coloring or tab completion to have a better experience in PowerShell.
  3. The common command for finding text in most windows applications is CTRL+F, you can use that or go the Edit menu and click, Find in Script.
  4. To locate text after the cursor, press F3, or on the Edit menu click the option Find Next in Script.
  5. Finding text before the cursor, either press F3 or go to the Edit menu and select Find Previous in Script.

Finding Text In The Script Pane

Finding And Replacing Text In The Script Pane

Simply press CTRL+H or you can go to the Edit menu and select the option Replace in Script. Enter the text you want to find following the text you want it to replace, and press Enter.

These are some of the basic that you can learn to get started with Windows PowerShell. There are many vendors which offer Microsoft PowerShell Certification programs for users who are looking to complete their ITSM training with complete understanding of the program. Get ahead of the IT employment curve and never stop learning.

Previous Post Next Post
Hit button to validate captcha