PowerShell Magazine has started the PowerShell Experts Video Series, a series of short video interviews conducted at the PowerShell Deep Dive conference in Frankfurt, Germany.
Starting today, we will post one video interview per day. The first one is with MVP Dmitry Sotnikov.
PowerShell 3.0 CTP1 includes many new language enhancements. Here are four of them for advanced functions.
CmdletBinding and Parameter attributes
We are no longer required to assign a value of $true to CmdletBinding and Parameter attributes. For example, in v2 we had to write:
In v3 we can omit the assignment.
The absence of an attribute is same as explicitly setting the attribute to $false, but that isn’t new to v3, is the same as v2.
Built-in support for Paging operations
When the SupportsPaging attribute of CmdletBinding is specified in advanced functions we get three additional parameters IncludeTotalCount,Skip, and First. These parameters allows us to page the results. When the IncludeTotalCount is specified the function writes to the host the total amount of objects in the form of:
Total count: n
The Skip parameter, UInt64, controls how many objects the function ignores. The value cannot be greater than the total amount of objects in the result. The First parameter, UInt64, controls how many objects the function returns from the beginning of the result.
You can find a script example in the samples folder of CTP1 (Samples\WindowsPowerShell\SupportsPagingSample\SupportsPaging01.ps1).
Assign it a web URL and Get-Help will pick it up when the Online switch has been specified, and will
display the page in your default browser. Get-Command also shows the URI in its result.
Setting PositionalBinding to $false allows us to disable positional parameters binding and force users to write the parameter name and its value. See this post for more information.