This section looks at new features within the basic PowerShell Language. The aim of the team for V3 has been to remove the "scripting wall,"
Now there is a built-in alias for Select-String. This is sls. # Exampleof select string new alias sls -path c:\test.txt -pattern 'Hello'
In PowerShell 1 and 2, we have the -contains and -notcontains operator. In addition to this, we now have the -in and -notin operators, which works similarly, but the opposite way around: # Example 1: $value = 3 if ($value -in (1,2,3)) {"The number $value is a member of the array"} # Example 2: 4 -notin (1,2,3) #prints True
In V2. the ISE had three panes - a script pane, a command pane and an output pane. You typed commands into the command pane, but saw the output within the output pane. There were related $PSISE features to manage these. In V3, the output and command pane are merged so that they resemble the normal shell.
By default, the new ISE opens the Command Pane on the right-hand side of the screen by default. Some may find this annoying. To turn it off, un-check "Show Commands" in the "View" menu of the ISE.
Get-Command will now let you search for commands in three different ways:
1. By Command Type
Types available are: Alias, Function, Filter, Cmdlet, ExternalScript, Application, Script, Workflow, All
2. By Command Capability
Capabilities available are: Unknown, Cmdlet, Script, Workflow, CIM, ScripFile, Application The ability to search by Capability is a new feature of Get-Command.
3. By Command Verb and/or Noun and Module
See the following article on examples of the various usages of this command: Get-Command Examples
Note, too, that Get-Command will list all the commands available from all installed modules, regardless of whether the modules have been loaded into the current session or not.
Parameter
Description
Wait
Prevents any further commands from running until the specified computers have restarted.
For
Considers the computer to have restarted when the specified resources are available. Valid values are WMI, WinRM, and PowerShell.
Timeout
Specifies the amount of time (in seconds) to wait for the computer to restart. When the timeout interval expires, subsequent commands are run even if the computer is not restarted.
Delay
Determines how often Windows PowerShell queries the service that is specified by the For parameter to determine whether it is available after the computer is restarted. The default value is 5 (seconds).
Get-Content now has a -Raw parameter, which causes it to read text files in a text stream, keeping newline character intact. The resulting type is different too: Get-Content returns a string type, instead of and array type, when the -Raw switch parameter is specified.
# Output: IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object
Out-GridView now has three additional parameters: Wait, PassThru, and OutputMode. Of these, OutputMode is the most interesting. Wait simply does what it says: It will wait until the Out-Gridview window is closed before continuing code execution.
OutputMode has three options: Single, Multiple, or None. None is not useful, because it causes Out-Gridview to behave as if you had not specified -OutputMode. But Single and Multiple allow you to select from a list, and this selection will be passed further down the pipeline. Edit (@mjolinor) The None value seems useless, because it causes the cmdlet to behave as if you had not specifice -OutputMode at all. I now believe it was necessary to include this option because of the Default Parameter Values feature. Used in command line work, the cmdlet is most useful with an Output mode of "Multi". This option allows multiple or single item select (but does not enforce single item selection). To make this the default, add it to the default parameter definitions: $PSDefaultParameterValues = @{'Out-Gridview:Outputmod'='Multi'} Having done this, you will now need to explicitly use -OutputMode None if you want Out-Gridview to operate in the normal default manner. An example of this is as follows: We call Get-Process with no arguments, to present an Out-Gridview of all the running processes. The user can then select either a single item (Single), or multiple items (Multiple), and when the user clicks OK, these selected items are sent down the pipeline for further processing, in this case to send these to Get-Process again for more detail.
# Example: Get-Process | Out-GridView -OutputMode Multiple | Get-Process | Format-List *
If the user clicks Cancel, nothing is passed down the pipeline.
PowerShell V3 Guide PowerShell V3 New Features
This article was originally written by @Bigteddy, with significant edits by @DoctorDNS
Great information. Thanks for putting this together.
Thanks, Richard. I'm sure all this will be properly documented when ver. 3 is officially released, but these are just useful novelties that I come across while working with the CTP release. I'm sure there's a whole book that could be written to comprehensively cover all the new features.
I just found this Wiki with Ver. 3 links:
social.technet.microsoft.com/.../powershell-v3-featured-articles.aspx
A nice article, thank you.
There is a good video of PowerShell V3 from Marc van Orsouw, MVP at technet Edge.
technet.microsoft.com/.../hh533298
Nice! Great job, Bigteddy! This should be nominated to be featured. Thanks!
Nice one, great information regarding PowerShell v3
This post is a great starting point for anyone looking for PowerShell v3 information
I do not understand adding en-US to every title. It makes no sense. The system culklture wuill select the correct culture on a mutlicultural web site.
This is normally accomplished via the URL. Adding this to the titles accomplishes nothing.
If your culture is other than en-US then you will likely see different pages perhaps with an option to view other culture pages.
There is currently only one PowerShell 3 and that is en-US. That will not likely change until beta.
Thomas, thanks very much for the re-formatting job you did. It's fantastic. It makes me a bit nervous to add more content, because I really battle with the editor. And now with Beta, I have quite a few little interesting new items...