What's New in CTP of PowerShell 2.0

PowerShell Team

 

As you start to play with the CTP bits of Windows PowerShell 2.0, it would be wise to tell what’s new in this CTP release. 

First thing to know is that this release is compatible with and replaces Windows PowerShell 1.0. You must un-install PowerShell 1.0 to install this CTP release.

Uninstalling Windows PowerShell 1.0

·         Windows XP-SP2 and Windows Server 2003: Under Add/Remove Program, select the option to show updates. Remove the PowerShell updates as applicable for your system: KB926139 (en-us),KB926140 (localized), KB926141 (MUI pack)

·         Windows Vista: Go to Control Panel->Program and features->Installed Updates. Uninstall the PowerShell update: KB928439

·         Windows Server 2008: Starting with Beta3 of Windows Server 2008, PowerShell 1.0 comes as an in-band optional component. If you have enabled PowerShell 1.0, you must turn the feature off before you can install PowerShell V2 CTP. Launch Server Manager and choose the option to remove Features. Select PowerShell from the list and disable the feature.

Breaking Changes from Windows PowerShell 1.0

·         The value of the PowerShellEngine key under HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine has been changed to 2.0

·         New language Keywords Data and Cmdlet have been added. What this means is that commands named ‘data’ or ‘cmdlet’ will be interpreted as language Keywords which will result into parse errors.

·         Changes in Argument separator behavior. In PowerShell 1.0, $a.method(,1) is treated as a call with an array of 1 element but $a.method(1,,2) as a parse error. In PowerShell 2.0, both are treated as parse errors.

·         New Cmdlets, variables have been added (listed below). These can conflict with existing variables and functions. 

 

1.       PowerShell Remoting

Windows PowerShell 2.0 provides support for executing Cmdlets and Scripts remotely. PowerShell Remoting allows managing a collection of remote machines from a single client. Managing remote computers using PowerShell 2.0, requires that PowerShell 2.0 be installed on all the computers taking part in the operation; that is the client computer and the computer(s) being managed.

For more information:

·         get-help About_Remoting

·         get-help Invoke-Expression

 

Enable Remoting: PowerShell Remoting feature relies on Windows Remote Management (WS-Man) technology. In order for remoting to work, make sure that the WS-Man Winrm service is installed and started. To verify that Winrm service is running, do the following:

                                PS> get-service winrm

Setup places a PowerShell script (Configure-Wsman.ps1) in $pshome folder that configures WS-Man settings. To configure WS-Man for PowerShell remoting feature, please run the configure-WSMan.ps1 script from PowerShell folder (run elevated for Windows Server 2008 or Windows Vista SP1). This script does not start or stop WinRM service.

                & $pshome\Configure-Wsman.ps1

Known issue: 

·         To use Remoting Cmdlets and features, PowerShell must be started as administrator/elevated. 

      ·         PowerShell 2.0 Remoting features will not work correctly on Windows Vista RTM. Please install Windows Vista Service Pack 1 (SP1) Beta to enable PowerShell Remoting features.

2.       Background Jobs

Windows PowerShell 2.0 introduces the concept of a background job (PsJob).  A PsJob runs a command or expression asynchronously and “in the background” without interacting with the console. The command prompt returns immediately and you can query for the job results at your convenience.  You can run background jobs on a local or remote computer.

For more information:

·         get-help About_PSJob

 

3.       ScriptCmdlets

ScriptCmdlets allow you to write cmdlets in PowerShell script, rather than compiled C# and VB.NET code.

Known issue: 

For this release, following cmdlet parameters are not supported:

·         Parameter sets

·         Help

 

For more information:

·         get-help about_scriptcmdletparameters

·         get-help about_scriptcmdletmethods

·         get-help about_scriptcmdletattributes

 

4.       Steppable Pipelines

This feature allows turning a script-block into a steppable pipeline and then controlling the sequence of activities by individually calling Begin(), Process() and End() on the pipeline.

5.       Data Language

The data language is a subset of the PowerShell language that allows better sharing of scripts. It also allows better separation of data from the rest of the code in your script.

For more information:

·         get-help about_data_section

·         get-help ConvertFrom-StringData

 

6.       Script Internationalization

This new feature allows PowerShell script authors to write scripts that can be translated to any language supported by Windows.

You can separate string resources from the rest of the code, using the new data language feature (above). Using the new Import-LocalizedData cmdlet, you can instruct PowerShell to check the operating system’s UI culture, check for a translated data file (.psd1) in the proper culture folder (such as en-US, or de-DE), and replace the original strings with the translated ones.

For more information:

·         get-help about_script_internationalization

·         get-help Import-LocalizedData

·         get-help ConvertFrom-StringData

·         get-help about_data_section

 

7.       Script Debugging

New debugging features have been added: You can now set breakpoints on lines, columns, functions, variables, and commands. You can also specify actions to run when the breakpoint is hit. Stepping into, over, or out of functions is also supported. You can also get the call stack.

For more information:

·         get-help about_debugger

 

8.       New Operators:

·         Splatting operator (@): PowerShell V2 supports splatting operator (@) to pass a collection of parameters

·         -Split: The -split operator enables a user to split a string into an array of substrings, based on a separator.

·         –Join: The -join operator concatenates multiple strings from a string array into a single string, separated by the separator.

 

9.       New Variables:

·         $commandLineParameters: Accumulates command-line and pipeline parameters. Cmdlets can access it through MyInvocation.CommandLineParameters.

·         $PSVersionTable: PowerShell version information is available through this variable

·         $Culture: Current Culture information is available through this variable

·         $UICulture: Current UI Culture information is available through this variable

 

10.   New Cmdlets:

Following 24 cmdlets have been added in PowerShell 2.0. See help for these Cmdlets for details about how to use them.

Get-PSBreakpoint

Get-PSCallStack

Remove-PSJob

New-PSBreakpoint

ConvertFrom-StringData

Start-PSJob

Disable-PSBreakpoint

Import-LocalizedData

Stop-PSJob

Enable-PSBreakpoint

Get-Runspace

Wait-PSJob

Remove-PSBreakpoint

New-Runspace

Invoke-WMIMethod

Step-Into

Remove-Runspace

Remove-WMIObject

Step-Out

Get-PsJob

Set-WMIInstance

Step-Over

Receive-PSJob

Out-GridView

 

11.   Constrained Runspaces:

Constrained Runspaces allows creation of PowerShell Runspaces with a set of Constraints. Constraints include the ability to restrict access and execution of Commands, scripts, and language elements when using the Constrained Runspace.

12.   RunspacePools

Support has been added for RunspacePools. RunspacePools enables concurrent execution of commands by efficiently managing a pool of runspaces on behalf of the user. See the SDK documentation for more details about how to use RunspacePool APIs.

13.   Parser Tokenizer API

Another new feature in this release is the Parser Tokenizer API which lets you determine the Tokens associated with a PowerShell script. This API enables many scenarios such as building syntax color highlighters, making your scripts production ready by expanding aliases and so on. See SDK documentation for more details about how to use the API. 

14.   New PowerShell Hosting APIs

The release introduces new APIs which simplifies Hosting PowerShell Engine in your Applications and building GUI Management applications on top of PowerShell Cmdlets. Please see the SDK documentation for the new APIs.

15.   Metadata APIs for Command and Parameters

New APIs allow access to command and parameter metadata (similar to the metadata obtained in the shell via get-command). This metadata can be used to automate generation of stub ScriptCmdlet code from Cmdlet Type.

16.   Graphical PowerShell

This release includes a very early alpha version of the new graphical shell. A feedback button has been placed on the toolbar to hear your feedback, so please use it to report bugs, likes and dislikes. If you do not have a mail client installed, send feedback to gPSfback@microsoft.com. This feature requires Microsoft .NET Framework 3.0.

 

Features:

·         An interactive shell with syntax coloring and Unicode support.

·         A multi-tabbed scripting pane for loading / composing multiple ps1 files.

·         The ability to run (dot-source) a script by pressing <F5>, or by clicking the “Run” on the toolbar.

·         The ability to run (dot-source) parts of a script by selecting the desired parts and pressing <F5>, or clicking “Run” on the toolbar.

·         Multiple runspaces (shells): You can open up to eight runspaces inside Graphical PowerShell, by using the “Shell” menu, or pressing the tab “stub” when it becomes visible (after the second runspace)

 

Known issues:

·         There is no support for any commands that require user input, including legacy commands, such as: netsh, telnet, ftp, nslookup etc.

·         There is no support for Tab Completion.

·         PSHost functionality is not supported.

·         Text output still has the ellipses (…) although the screen is wide enough to display more textThe script editor is slow for large files (> 1,000 lines)

 

17.   Out-GridView

The new Out-GridView cmdlet displays the results of other commands in an interactive table, where you can search, sort, and group the results. For example, you can send the results of a get-process, get-wmiobject, or get-eventlog command to out-gridview and use the table features to examine the data. This feature requires Microsoft .NET Framework 3.0.

For more information:

·         get-help out-gridview

 

Known issue:

·         The command output that you send cannot be pre-formatted, such as by using the Format-Table or Format-Wide commands.

 

18.   Improvements in Windows PowerShell V2

Changes to TabExpansion function: The TabExpansion function now only shows unique parameters and lists them in sorted order. 

New parameters added to Select-String: Select-String cmdlet now supports new parameters, such as:

o   -Context: This allows you to see lines before and after the match line

o   -AllMatches: which allows you to see all matches in a line (Previously, you could see only the first match in a line)

o   -NotMatch: Equivalent to grep -v

o   -Encoding: to specify the character encoding

Updated Type Adapters: Member lookup algorithm for Type Adapters has been updated to include Base members. Members on the Base Object for Adapted types are now directly accessible on the object. This removes the need to use PSBASE property to access base members.

Improvements to Get-Member: Get-Member cmdlet now supports a –View and –Force parameter. Valid values for –View parameter are “Extended, Adapted, Base, All”. The default value is “Extended,Adapted”. Getter and Setter Methods are not shown by the default get-member output. Since adapted Types now expose Base members, use –view All to list Base members in the get-member output.

Improved ADSI support: ADSI adapter now allows access to Base Methods and Properties. [ADSISearcher] Type accelerator has been added for System.DirectoryServices.DirectorySearcher Class. Two CodeMethods, ConvertDNBinaryToString and ConvertLargeIntegerToInt64 have been added to DirectoryEntry type to simplify marshalling data between ADSI and PowerShell.

New parameters added to Get-WMIObject: Get-WMIobject cmdlet now supports following parameters -Impersonation, -Authentication, -Locale, -EnableAllPrivileges, -Amended, -DirectRead, -Authority.

The new parameters allow setting Authentication and Impersonation properties which are needed to make secure connections to a remote computer.

Improved Bitwise Operators: The Bitwise operators now work with Int64

19.   New PowerShell APIs

This release provides new APIs for programmatic access to many of the features listed above. See SDK documentation available on download center for a complete list of new Types and APIs. The following is a quick summary of Key APIs and related features to help you get started.

 Note: This is a pre-release drop and the Type Names and APIs are subject to change.

Feature Area

Related Types

Hosting, RunspacePools

System.Management.Automation.Runspaces.PowerShell, System.Management.Automation.Runspaces.PSDataCollection, System.Management.Automation.Runspaces.RunspacePool

System.Management.Automation.Runspaces.PSCommand

Parser Tokenizer

System.Management.Automation.PSParser, System.Management.Automation.PSToken, System.Management.Automation.PSTokenType, System.Management.Automation.PSParseError

Constrained Runspaces

System.Management.Automation.Runspaces.InitialSessionState

System.Management.Automation.Runspaces.SessionStateAssemblyEntry

System.Management.Automation.Runspaces.SessionStateCmdletEntry

System.Management.Automation.Runspaces.SessionStateProviderEntry

System.Management.Automation.Runspaces.SessionStateScriptEntry

System.Management.Automation.Runspaces.SessionStateAliasEntry

System.Management.Automation.Runspaces.SessionStateApplicationEntry

System.Management.Automation.Runspaces.SessionStateFunctionEntry

System.Management.Automation.Runspaces.SessionStateVariableEntry

MetaData APIs

System.Management.Automation.ProxyCommand, System.Management.Automation.CommandMetadata, System.Management.Automation.ParameterMetaData

 

0 comments

Discussion is closed.

Feedback usabilla icon