Microsoft PowerShell
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.
Contents
DataSelf's Microsoft PowerShell Knowledge Base
Powershell Scripts
- DataSelf's Microsoft PowerShell Knowledge Base (New Pages)
- PS Run Excel AD AD for Excel - DataSelf's other Automatic Distribution system
PowerShell Language
Powershell language reference and concepts.
- Master-PowerShell with Dr. Tobias Weltner A good text on the language although not always complete.
- Microsoft Connects's Windows PowerShell Customer Connection Includes links to more PowerShell resources from Microsoft
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.
- Run Windows Powershell
(Start > type "Powershell" into search box) - 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
- Microsoft page about_Execution_Policies
- http://technet.microsoft.com/en-us/library/hh847736.aspx
- http://ss64.com/ps/powershell.html
PowerShell ISE
- http://windowsitpro.com/scripting/get-know-powershell-ise
- Wildcards can be used in some dialog boxes.
- Asterisk (*) represents any number of characters
- Question mark (?), represents a single character.
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
- https://github.com/proxb/RegExHelper RegEx Helper (PS script)