{"id":18566,"date":"2020-08-17T14:33:46","date_gmt":"2020-08-17T22:33:46","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/powershell\/?p=18566"},"modified":"2020-08-17T14:33:46","modified_gmt":"2020-08-17T22:33:46","slug":"powershell-7-1-preview-6","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/powershell-7-1-preview-6\/","title":{"rendered":"PowerShell 7.1 Preview 6"},"content":{"rendered":"<p>Today, we are releasing the <a href=\"https:\/\/github.com\/PowerShell\/PowerShell\/releases\/tag\/v7.1.0-preview.6\">sixth preview of the PowerShell 7.1 release<\/a>!<\/p>\n<p>Further in this blog post I&#8217;ll provide details on some important changes you should be aware of as you\nstarting trying out this preview.<\/p>\n<h2>PowerShell 7.1 Roadmap update<\/h2>\n<p>We are planning the last preview release around the first week of September.\nThis will allow us to get in the last of our significant code changes before we start minimizing risk (and code churn) for our Release Candidate.<\/p>\n<p>We expect our first Release Candidate in the second half of September.\nRelease Candidates are &#8220;go-live&#8221; meaning they are supported in production.\nIf there is a critical security or blocking issue, we will provide an updated servicing release for a\nRelease Candidate.\nWe would like users to start deploying the Release Candidate so that we can address any major issues\nas we head towards a General Availability release at the end of this year.<\/p>\n<p>Unlike preview releases, Release Candidates will <em>not<\/em> have Experimental Features enabled by default.\nSome Experimental Features will be taken out of experimental state and their designs will be considered\nfinal while others will stay in experimental state and will need to be explicitly enabled to continue use.<\/p>\n<p>As a reminder, Experimental Features are not considered design complete.\nThis means that the design may change based on real world usage feedback and such changes are not\nconsidered breaking changes.\nProduction code should not depend on experimental features.<\/p>\n<h2>Noteworthy Changes<\/h2>\n<p>There are some changes in PowerShell 7.1 Preview 6 that are worth going into detail and some are breaking changes.<\/p>\n<h3>Rename <code>-FromUnixTime<\/code> to <code>-UnixTimeSeconds<\/code> on <code>Get-Date<\/code> to allow Unix time input<\/h3>\n<p><a href=\"https:\/\/wikipedia.org\/wiki\/Unix_time\">Unix time<\/a> is the number of seconds since January 1st, 1970 at 00:00:00 UTC.\nIn Preview 2 of PowerShell 7.1, we merged a community submitted pull request to add <code>-FromUnixTime<\/code> to the <code>Get-Date<\/code> cmdlet.\nHowever, it was discovered later that the prefix <code>From<\/code> was inconsistent with existing parameters on that cmdlet.\nSo a change was accepted to simply call it <code>-UnixTimeSeconds<\/code> which accepts a value in Unix time similar to how\n<code>-Date<\/code> accepts a value in date time format.<\/p>\n<pre><code class=\"powershell\">get-date -UnixTimeSeconds 1597615564\r\n<\/code><\/pre>\n<pre><code class=\"powershell-console\">Sunday, August 16, 2020 3:06:04 PM\r\n<\/code><\/pre>\n<p>This feature was added by community member <a href=\"https:\/\/github.com\/aetos382\">aetos382<\/a>!<\/p>\n<h3>Make <code>$ErrorActionPreference<\/code> not affect <code>stderr<\/code> output of native commands<\/h3>\n<p>Native commands support three streams: stdin, stdout, and stderr.\n<code>stdin<\/code> is for sending input to a native command.\n<code>stdout<\/code> is for any output from a native command you might want to pass further down the pipeline.\n<code>stderr<\/code> (despite &#8220;error&#8221; being in the name) is used for all other output.<\/p>\n<p><code>stderr<\/code> can include error messages, but also text content equivalent to PowerShell verbose, debug, and information streams\nas well as progress information or help text.<\/p>\n<p>The de facto standard way to determining if a native command has succeeded or failed is by looking at the exit code\n(in PowerShell this is by the <code>$LASTEXITCODE<\/code> automatic variable).\nSince <code>stderr<\/code> typically contains non-error information, it is not a reliable way to detect errors from native commands.<\/p>\n<p>Text output from <code>stderr<\/code> are wrapped as <code>ErrorRecord<\/code>s but tagged to indicate it is from stderr.\nPrior to this change, because these are <code>ErrorRecord<\/code> instances, they would get added to the <code>$Error<\/code> automatic variable\nwhich is a running log of errors.\nIf you set <code>$ErrorActionPreference<\/code> to a value that affects execution (like <code>Stop<\/code> or <code>Inquire<\/code>) then any text written\nto <code>stderr<\/code> would cause your script execution to be impacted.<\/p>\n<p>With this change, <code>stderr<\/code> is just treated like an information stream (although it is still stream number 2 for redirection) and\nis not affected by <code>$ErrorActionPreference<\/code> which also means <code>stderr<\/code> output does not show up in <code>$Error<\/code> nor does it\ncause <code>$?<\/code> to be <code>$false<\/code> indicating the last command failed.<\/p>\n<p>There is an existing <a href=\"https:\/\/github.com\/PowerShell\/PowerShell-RFC\/pull\/88\">RFC<\/a> to allow script execution to be impacted\nby native command exit code that we hope to be in a future version of PowerShell.<\/p>\n<h3>Allow explicitly specified named parameter to supersede the same one from hashtable splatting<\/h3>\n<p><a href=\"https:\/\/docs.microsoft.com\/powershell\/module\/microsoft.powershell.core\/about\/about_splatting\">Splatting<\/a> is a feature in\nPowerShell allowing passing parameters to commands defined in a hashtable.\nFor example, if you have a script that calls the same or different cmdlets multiple times where the parameters and their\nvalues are the same, then instead of typing it multiple times you can define it once and pass the same hashtable\nto each cmdlet.\nIf a parameter or value changes, you would then just update the hashtable.<\/p>\n<pre><code class=\"powershell\">$myParams = @{\r\n  Uri = 'https:\/\/api.github.com\/repos\/powershell\/powershell\/releases'\r\n  Method = 'Get'\r\n  FollowRelLink = $true\r\n}\r\n\r\nInvoke-RestMethod @myParams\r\n<\/code><\/pre>\n<blockquote>\n<p>Note: The above example shows how to pass the <code>-FollowRelLink<\/code> switch using splatting<\/p>\n<\/blockquote>\n<p>In some scripts, you may want to override one of the values in the hashtable for a specific instance.\nPreviously, you would get an error that the parameter was already specified:<\/p>\n<pre><code class=\"powershell\">Invoke-RestMethod @myParams -Uri https:\/\/api.github.com\/repos\/dotnet\/runtime\r\n<\/code><\/pre>\n<pre><code class=\"powershell-console\">Invoke-RestMethod: Cannot bind parameter because parameter 'Uri' is specified more than once. To provide multiple values to parameters that can accept multiple values, use the array syntax. For example, \"-parameter value1,value2,value3\".\r\n<\/code><\/pre>\n<p>With this change, the above example now works as one would expect in that the <code>-Uri<\/code> parameter value will be the one explicitly\nspecified in the command line and not the one in the hashtable.<\/p>\n<h3>Experimental Feature: PSManageBreakpointsInRunspace<\/h3>\n<p>PowerShell has powerful built-in scripting <a href=\"https:\/\/docs.microsoft.com\/powershell\/module\/microsoft.powershell.core\/about\/about_debuggers\">debugging capabilities<\/a>.\nHowever, previously the debugging cmdlets would only allow you to manage breakpoints in the current PowerShell session (called a runspace).\nCommunity member <a href=\"https:\/\/twitter.com\/Poshoholic\">Kirk Munro<\/a> added the ability to specify a different runspace to the breakpoint management cmdlets!<\/p>\n<pre><code class=\"powershell\">$job = Start-Job { $pid; Start-Sleep -Seconds 5; Write-Verbose \"Hello\" }\r\n\r\n# wait until the job process starts\r\nwhile ($job.ChildJobs[0].Runspace.RunspaceStateInfo.State -ne 'Opened') {\r\n    Start-Sleep -Milliseconds 50\r\n}\r\nSet-PSBreakpoint -Command Write-Verbose -Action { break } -Runspace $job.ChildJobs[0].Runspace\r\n\r\n# wait until the job is waiting at the breakpoint\r\nwhile ($job.State -ne 'AtBreakpoint') {\r\n    Start-Sleep -Seconds 1\r\n}\r\n\r\n# get the job process id to debug it later\r\n$jobpid = $job | Receive-Job\r\n$job | Get-Job\r\n<\/code><\/pre>\n<pre><code class=\"powershell-console\"><br \/>Id     Name            PSJobTypeName   State         HasMoreData     Location             Command\r\n--     ----            -------------   -----         -----------     --------             -------\r\n7      Job7            BackgroundJob   AtBreakpoint  True            localhost             Start-Sleep -Seconds 5;\u2026\r\n\r\n<\/code><\/pre>\n<pre><code class=\"powershell\"># Connect to the running job process\r\nEnter-PSHostProcess -id $jobpid\r\n\r\n# Find the runspace where the running script is stopped at the breakpoint and attach debugger to it\r\nGet-Runspace | Where-Object { $_.Debugger.InBreakpoint -eq $true } | Debug-Runspace\r\n<\/code><\/pre>\n<pre><code class=\"powershell-console\">Debugging Runspace: RemoteHost\r\nTo end the debugging session type the 'Detach' command at the debugger prompt, or type 'Ctrl+C' otherwise.\r\n\r\nHit Command breakpoint on 'Write-Verbose'\r\n\r\nAt line:1 char:32\r\n+  $pid; Start-Sleep -Seconds 5; Write-Verbose \"Hello\"\r\n+                                ~~~~~~~~~~~~~~~~~~~~~\r\n<\/code><\/pre>\n<p>Here you see that execution stopped exactly where we set the breakpoint.<\/p>\n<blockquote>\n<p>Note: As the script is stopped at the breakpoint, it will wait indefinitely for a debugger to be attached<\/p>\n<\/blockquote>\n<h3>Built in Pager for Get-Help<\/h3>\n<p>As part of additional work to improve the PowerShell help experience (more on this later!), we wrote our own pager to provide a consistent\nexperience across platforms.<\/p>\n<p>This is a work in progress so a bit limited in functionality currently.\nContributions and issues are certainly welcome in the <a href=\"https:\/\/github.com\/powershell\/pager\">Pager repo<\/a>.<\/p>\n<p>You can try it out using the new <code>-Paged<\/code> switch with <code>Get-Help<\/code>:<\/p>\n<pre><code class=\"powershell\">Get-Help -Paged Get-Command\r\n<\/code><\/pre>\n<p>PSReadLine will leverage this pager for its new &#8220;Dynamic Help&#8221; feature where you can use a keyboard combination to get help while in the middle\nof typing out a command-line and being able to return to exactly where you left off!<\/p>\n<h3>New <code>-MaskInput<\/code> switch for <code>Read-Host<\/code><\/h3>\n<p>This was a community requested feature to hide the input the user types.\nNormally, you would use <code>-AsSecureString<\/code> for sensitive information that you would not want echoed onto the screen or end up in logs\/transcripts.\nHowever, there are scenarios where you don&#8217;t want to deal with a SecureString and prefer to get plain text.\nThis switch will still mask the input the user types, but returns a string.<\/p>\n<pre><code class=\"powershell\">$input = Read-Host -MaskInput -Prompt \"Tell me a secret\"\r\n<\/code><\/pre>\n<h2>Summary<\/h2>\n<p>There are, of course, many bug fixes and smaller improvements not mentioned in this blog post provided by both the community as well\nas the PowerShell team.\nWe have a few more important changes to get into the PowerShell 7.1 release before we hit our first Release Candidate in September.<\/p>\n<p>Early this month, the majority of PowerShell usage (not including Windows PowerShell) switched from PowerShell Core 6.2 to PowerShell 7.0!\nWe hit a high point of 4.5 million startups of <code>pwsh<\/code> in a single day!\nSee more data at our public <a href=\"https:\/\/aka.ms\/psgithubbi\">PowerBI dashboard<\/a>.\nReminder that PowerShell Core 6.2 support ends next month!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update on PowerShell 7.1 release<\/p>\n","protected":false},"author":685,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[248],"class_list":["post-18566","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","tag-powershell"],"acf":[],"blog_post_summary":"<p>Update on PowerShell 7.1 release<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/18566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/685"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=18566"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/18566\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=18566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=18566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=18566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}