Robert Praetorius

My feedback

  1. 2 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    1 comment  ·  PowerShell » PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
    Robert Praetorius commented  · 

    I have a fairly short reproducer now:

    $remoteHostName = Read-Host 'Remote Host Name'
    $remoteSession = New-PSSession $remoteHostName -Credential (Get-Credential)

    Invoke-Command $remoteSession {
    New-Module -ScriptBlock {
    $Script:sawError = $false
    filter Notice-Error {
    if ($_ -is [System.Management.Automation.ErrorRecord])
    {
    $Script:sawError = $true
    Write-Error -ErrorRecord $_
    }
    else { $_ }
    }
    } -Function Notice-Error
    }
    Invoke-Command $remoteSession {&{0/0} 2>&1 | Notice-Error}
    Remove-PSSession $remoteSession

    This breaks pretty reliably with different (recent) versions of Windows on the other end. A slightly ugly workaround is to append 2>&1 to Write-Error (this mangles the serialization of the ErrorRecord, but most of the information can be recovered). Intriguingly (or not), the overflow doesn't happen with Enter-PSSession and it doesn't happen in remote tabs in PowerShell ISE and I have yet to find any conditions where the overflow happens in a local session.

    Robert Praetorius shared this idea  · 
  2. 5 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    1 comment  ·  PowerShell » PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
    Robert Praetorius commented  · 

    Note that calling the static methods in System.Linq.Enumerable from PowerShell is not difficult (at least for fairly modern versions of PowerShell). The main thing you need to do is talk to PowerShell in a way that it understands what overload to select and what generic arguments to use. For example, while PowerShell gives up on [System.Linq.Enumerable]::Union((1,2,3),(2,3,4)), it has no trouble with [System.Linq.Enumerable]::Union([int[]](1,2,3),[int[]](2,3,4)). Things get a little trickier with predicates, but are still quite doable. I haven't messed with Expression trees and IQueryable in PowerShell, so I can't comment intelligently on that, but I suspect it's also doable.

    All that said, native support for LINQ syntax in PowerShell would be a delightful thing to have.

Feedback and Knowledge Base