Microsoft PowerShell

From DataSelf Knowledge Base
Jump to: navigation, search

{{#breadcrumb:Main Page }} Microsoft's recommended scripting language. Although designed with Windows administration particularly in mind, PowerShell also can function as general scripting language. Unfortunately, the scripting language aspect of Powershell seems to receive less attention from the vendor.

hello

PowerShell Language

Powershell language reference and concepts.


Understanding Powershell Modules

Get-Command -Module

Installing

Determining the Version of Powershell

If the $PSVersionTable variable doesn't exist, then you are running V1. If it does exist, then the version info will be available from $PSVersionTable.

  1. Run Windows Powershell
    (Start > type "Powershell" into search box)
  2. Type '$PSVersionTable' at prompt. (not case sensitive)
  • If the $PSVersionTable variable doesn't exist, then you are running Powershell version 1.
  • If $PSVersionTable does exist, then the version info will be displayed. (See the value for "PSVersion").

Alternatives:

function Get-PSVersion {

if (test-path variable:psversiontable) {$psversiontable.psversion}
else {[version]"1.0.0.0"}

}


Installing Powershell Version 3

Execution Policy

Powershell will not run scripts without the proper execution policy. By default unsigned scripts will not be run.

Duration

If you set the execution policy for the local computer (the default) or the current user, the change is saved in the registry and remains effective until you change it again.
Get-ExecutionPolicy -list
Lists the current execution policy
Set-ExecutionPolicy -ExecutionPolicy <PolicyName>
Changes the execution policy.
Put the following code in the profile for PowerShell ISE:
 Set-ExecutionPolicy -ExecutionPolicy Unrestricted

OR (recommended)

 Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Executing from the DOS command line

powershell.exe -ExecutionPolicy [Bypass|Unrestricted] -Command .\<PS-script>.ps1

PowerShell ISE


PSModulePath Environment Variable

New-PsDrive -Scope Global -Name MyMod -PSProvider FileSystem -Root (($env:PSMODULEPATH -split ";")[0])

PowerGUI Editor & .exe compiler

http://www.quest.com/powergui-freeware/


Links

Regex - Regular Expressions in Powershell