PowerShell

The PowerShell forum accepts bug reports as well as feedback and suggestions. For more information, check out the PowerShell Homepage

The following is a list of the states we use to track items.

status meaning
survey We saw this and we are considering it. Please upvote if it’s important to you.
needs more information We don’t understand the issue and need additional details.
investigating We are looking at this internally to understand things like: scenario, reproduction of issue, costing, or other technical details.
in queue The issue is understood and in our unprioritized backlog. Your votes will be used to drive prioritization of this work.
  • Hot ideas
  • Top ideas
  • New ideas
  • My feedback
  1. [BUG] Count property incorrect works with a single WMI object

    You can now use Count or Length on any object, even if it didn’t have the property. If the object didn’t have a Count or Length property, it will will return 1 (or 0 for $null). Objects that have Count or Length properties will continue to work as they always have.

    Returns nothing,but should be

    PS > (Get-WmiObject -Class Win32OperatingSystem).Count
    PS > (Get-CimInstance -ClassName Win32
    OperatingSystem).Count

    Works as expected

    PS > (Get-WmiObject -Class Win32OperatingSystem -Filter "Name=1").Count
    0
    PS > (Get-CimInstance -ClassName Win32
    OperatingSystem -Filter "Name=1").Count
    0
    PS > (Get-CimInstance -ClassName Win32Service).Count
    230
    PS > (Get-WmiObject -Class Win32

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →

    I can repro this for sure, but given the difficulty of servicing and the impact of the bug, it’s pretty unlikely to get fixed.

    One possible workaround: (Get-CimInstance -ClassName Win32_OperatingSystem -Filter “Name=1″ | Measure-Object).Count

  2. Allow Environment Variable as default value for function parameter.

    When defining a function, I would like to use an environment variable as the default value. If the environment variable exists and has a value that value will be used. For example,

    function Get-Info ([Alias("name")] [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true)] [string] $projectName = $env:Project_Name)
    {
    }

    Instead of having to passing in the Project Name for each call I would like to store it in an environment variable. When I do it would allow me to call Get-Info with no parameters and the value in the environment variable would be used. If the environment variable does not exist or is empty the user…

    17 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    3 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  3. PowerShell fails to start if path contains brackets

    In a variety of cases, attempting to launch PowerShell from a path containing square brackets either fails entirely, or fails to resolve the relative working directory. For example:

    With this command, PowerShell won't launch:

    PS C:\T[e]st> Start PowerShell

    Start : Cannot perform operation because the wildcard path C:\T[e]st did not resolve to a file.
    
    At line:1 char:1
    + Start PowerShell
    + ~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (C:\T[e]st:String) [Start-Process], FileNotFoundException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.StartProcessCommand

    From CMD or Powershell, this command starts Powershell, but with the wrong working directory:

    C:\T[e]st> PowerShell

    Windows PowerShell
    
    Copyright (C) 2015 Microsoft Corporation. All rights reserved.

    PS…

    6 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  1 comment  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  4. Bug: Workflow -> InlineScript -> Function -> Function -> Write-Verbose throws an uncatchable and fatal exception

    I've blogged about this with full examples here: https://www.codykonior.com/2016/08/31/if-you-dont-mind-me-saying-powershell-workflows-are-awfully-broken/


    1. If you have a workflow and call it with -Verbose

    2. If that workflow has an InlineScript which calls a function

    3. And that function calls another function which does a Write-Verbose

    A terminating, uncatchable exception is thrown:

    Object reference not set to an instance of an object.

    + CategoryInfo          : ResourceUnavailable: (:) [], ParentContainsErrorRecordException
    
    + FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException
    + PSComputerName : [localhost]

    It seems to be with how Write-Verbose gets overridden in workflows to prefix output with the computer name it's running on. Creating a Write-Verbose wrapper around itself alleviates the issue.

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  5. pipelinevariable vs outputvariable processing bug

    PS C:\Users\Administrator\Downloads\Lync\Lync> $outputtest = $null

    PS C:\Users\Administrator\Downloads\Lync\Lync> get-process -PipelineVariable pipelinetest -OutVariable outputtest | ? {$outputtest.name -like "vmwp"}

    Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName


    617      31    48096      27688   170   371.03    328 vmwp                                                                                                                                                
    
    535 57 39700 17712 135 251.22 2124 vmwp
    541 57 9584 18932 135 234.36 2644 vmwp
    85 7 760 3736 20 0.05 592 wininit
    161 8 1488 6564 66 0.25 624 winlogon
    227 11 10744 14144 56 2.45 1200 WmiPrvSE
    238 15 6072 11876 70 0.64 3592 WmiPrvSE

    PS C:\Users\Administrator\Downloads\Lync\Lync> get-process -PipelineVariable pipelinetest -OutVariable outputtest | ? {$pipelinetest.name -like "vmwp"}

    Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id…

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  6. Please make -NoTypeInformation the default for Export-CSV

    I'm pretty sure that Export-CSV is used for creating Excel compatible files far more often than it is used for Serialising and Deserialising Type-consistent PS Objects.

    Alternatively / additionally adding a PS preference variable to set the default behaviour.

    I understand that this is simply a convenience thing, eliminating the need to add an extra parameter for the most common use case.

    6 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  7. Problem with scope in PowerShell

    If you run following snippet of code in PowerShell, variable $i and $l will be accessible in the global scope after the loop has exited.
    for($i=1; $i -le 3; $i++){$l = $i}

    Typically in programming languages, neither variable should be visible in global scope, only in the loop scope. There has been many instances where I have forgotten this is a thing in PowerShell and it has bitten me in the face in the form of runtime errors.

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

    We’ll send you updates on this idea

    survey  ·  2 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  8. Bug in Show-Command

    Scriptblock parameters are interpreted as a [bool] value and is shown as a listbox with values $true or $false

    Code to reproduce:

    Show-Command -Name Invoke-Command

    Scriptblock parameter is shown as a [bool] listbox

    Cheers

    Tore

    15 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  1 comment  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  9. Negation operator isn't IEEE floating point compliant

    $a = 0.0 ; $b = -$a ; $c = -1.0*$a

    1.0 / $b

    should produce [double]::NegativeInfinity but produces [double]::PositiveInfinity instead

    1.0 / $c

    this correctly produces [double]::NegativeInfinity

    It looks like PowerShell implements "-$a" as "0 - $a" which is incorrect for floating point types.

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  10. BUG: PSBoundParameters contains values from PREVIOUS pipeline input

    When writing functions that take ValueFromPipelineByPropertyName, and accepting pipeline input, if some of the pipeline input is missing some properties, PSBoundParameters contains the previous value... incorrectly reporting the parameter was passed in:

    For example:

    function Get-UserName {
    [CmdletBinding()]
    param(

    [Parameter(ValueFromPipelineByPropertyName,Mandatory)]
    
    $Last,

    [Parameter(ValueFromPipelineByPropertyName)]
    $First

    )
    process {

    if($PSBoundParameters.ContainsKey('First')) {
    
    Write-Host -Foreground Red $PSBoundParameters['First'] $PSBoundParameters['Last'] " " -NoNewLine
    $First[0] + $Last
    } else {
    $Last
    }

    }
    }

    $Users = [PSCustomObject]@{ First = "Ethan"; Last = "Hunt" }, [PSCustomObject]@{ First = "Jason"; Last = "Bourne" }, [PSCustomObject]@{ Last = "Bond" }

    $Users | Get-UserName

    9 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  11. Treat empty arrays as constants

    PowerShell's constant expression analyzer should recognize empty arrays as constants. i.e. these two should work:

    { param([ValidateSet(@())]$a) }

    Set-Variable -Option Constant emptyArray @()
    { param([ValidateSet($emptyArray)]$a) }

    Rather than complaining that empty arrays aren't constants.

    And the following should be much faster:

    @() should be equivalent to the constant Array.Empty<object>()

    Measure-Command { foreach ($null in 0..10000000) { $null = @() } }

    [int[]]@() should be equivalent to the constant Array.Empty<int>()

    Measure-Command { foreach ($null in 0..10000000) { $null = [int[]]@() } }

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  12. ValidateSet doesn't accept constants like it says it does

    When running the below script on Windows 10 PowerShell 5.0.10586.494, it crashes with an error stating that the argument isn't a constant even though it is:

    Set-Variable -Option Constant ConstantVariable 'c'
    Set-Variable -Option Constant ConstantArrayVariable @('c')

    function Test-ValidateSet {

    param(
    
    [ValidateSet($ConstantVariable)]
    $p1,

    [ValidateSet($ConstantArrayVariable)]
    $p2
    )

    }

    At C:\tmp\Test-ValidateSet.ps1:7 char:22
    + [ValidateSet($ConstantVariable)]
    + ~~~~~~~~~~~~~~~~~
    Attribute argument must be a constant or a script block.
    At C:\tmp\Test-ValidateSet.ps1:10 char:22
    + [ValidateSet($ConstantArrayVariable)]
    + ~~~~~~~~~~~~~~~~~~~~~~
    Attribute argument must be a constant or a script block.

    + CategoryInfo          : ParserError: (:) [], ParseException
    
    + FullyQualifiedErrorId : ParameterAttributeArgumentNeedsToBeConstantOrScriptBlock

    This is an important feature for me because I…

    4 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  13. SupportsShouldProcess adds help for cmdlets, but not functions

    When you add the SupportsShouldProcess property (CmdletCommonMetadata) to a C# cmdlet, it adds the WhatIf/Confirm parameters and their standard help descriptions.

    But, when you use the SupportsShouldProcess parameter of the
    CmdletBinding attribute in an advanced function, it adds the WhatIf and Confirm parameters, but it doesn't add the standard help descriptions for these parameters, as designed.

    Unless function authors add the help explicitly it doesn't exist, and then authors write their own help, so we end up with a multiplicity of descriptions of the same thing, which can be confusing to users. That's why we created the standard help.

    And,…

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  14. RunspacePool handle and memory leaks (no leaks in v2)

    Invoke the below script. In the infinite loop it creates runspace pools and
    uses them for invoking jobs. In the end of each iteration script outputs
    the process handle count and private memory size.

    In PS v5.1 the handle count and memory size constantly increase.
    In PS v2.0 these leaks are not observed.

    -----8<-----

    $sw = [System.Diagnostics.Stopwatch]::StartNew()
    
    $count = 0
    for() {
    $pool = [RunspaceFactory]::CreateRunspacePool(1, 2)
    $pool.Open()

    $ps1 = [PowerShell]::Create()
    $ps1.RunspacePool = $pool
    $job1 = $ps1.AddScript(&#39;&quot;job1 $(Get-Date)&quot;&#39;).BeginInvoke()

    $null = $job1.AsyncWaitHandle.WaitOne()
    $ps1.EndInvoke($job1)

    $ps1.Dispose()
    $pool.Close()

    ++$count
    $p = Get-Process -Id $PID
    &quot;$($p.HandleCount) $($p.PrivateMemorySize64 / 1mb) $($count / $sw.Elapsed.TotalSeconds)&quot;
    }

    -----8<-----

    3 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  15. [Bug] Castle's DynamicProxy breaks property indexers

    This blog post explains the issue is greater detail - https://matt.kotsenas.com/posts/powershell-dynamicproxy-indexers

    Setup:
    1. Create a C# class with an interface
    2. On that interface add a property indexer (and implement it in the class)
    3. Use Castle's DynamicProxy generator to create a proxy for that object

    Expected Results:
    - The proxy behaves like the regular object and the indexer works (e.g. $myObject['foo']

    Actual Results:
    - The proxy's indexer does not exist (e.g. $myObject['foo'] returns null)
    - The underlying getItem() method exists and works (e.g. $myObject.getItem('foo) returns the expected value)

    Here's a full implementation with sample code:

    ```
    $assemblies…

    3 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  16. Document two types of terminating errors

    PowerShell help describes errors as non-terminating and terminating.
    But it does not tell that there are two types of terminating errors.

    For example, "true terminating errors" are produced by throw in scripts.
    They terminate the current script AND the calling script.

    Other terminating errors terminate only the current pipeline and DO NOT
    terminate the calling script unless its $ErrorActionPreference='Stop'
    or there is try/catch/finally or trap somewhere in the call stack.

    Just one example. A missing command is such a semi-terminating error (help about_trap).
    More: https://github.com/nightroman/PowerShellTraps/tree/master/Basic/Errors-of-unusual-type

    In the following command Get-Date is invoked after the error and the exit code is…

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  17. ps5.0bug:please remove count length property from number object!

    ps5.0bug:please remove count length property from number object!

    Normal logic:
    There is no "count" and "length" attribute in the numeric type.

    【Cause of the bug】
    in my guess:
    powershell 1.0 developer:
    wrong add property "count" and "length" to number object,then make them equal to null.

    powershell 3.0 developer:
    then make them equal to 1.

    Joey Aiello [MSFT] (Program Manager, Windows Server):
    In PowerShell v3 the "Length" property was added to ALL objects. This was wrong.
    https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11087970-ps3-length-property-added-to-all-objects-should-be

    【bug with powershell version】
    powershell 5.0 in win10 10586.494: yes,tested.

    【test code in win10】
    $a = 1234777
    $a.gettype().fullname #system.int32
    $a.length #return 1
    $a.lengtha #return…

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  5 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  18. Code completion pollutes $Error

    PowerShell v5

    Start a clean session:
    PowerShell -NoProfile

    Type the following characters:
    [cmd=

    and press Tab. The code is not completed, this is fine.

    But the global error collection $Error contains an error:
    The specified wildcard character pattern is not valid: [cmd=*

    Code completion should avoid such noise errors. They distract and may make an
    illusion that some user code produces them. Time may be lost on finding the
    actual culprit.

    4 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  19. [Bug] New-PSSession returns null when executed from a non-console session

    Hi,

    We're seeing an issue where New-PSSession returns null when executed from a non-console session. Specifically, we have a top-level script that gets executed from Cake (http://cakebuild.net/) and Cake.Powershell (https://github.com/SharpeRAD/Cake.Powershell) within a TeamCity build agent.

    The top-level script is structured similar to:
    Set-StrictMode -Version Latest

    $Error.Clear()
    $ErrorActionPreference = "Stop"

    try
    {

    $remoteSession = New-PSSession `
    
    -ComputerName $FullyQualifiedDNSName `
    -UseSSL `
    -SessionOption (New-PsSessionOption -SkipCACheck -SkipCNCheck) `
    -Port 5986 `
    -Credential $credentials `
    -WarningAction Continue

    }
    catch
    {

    Write-Warning -Message ($_ | ConvertTo-CakeFormattedError)
    
    throw

    }

    When executed from Cake/Cake.Powershell via TeamCity, $remoteSession ends up being null. However, a…

    1 vote
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  1 comment  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
  20. Evaluate target enumeration names to distinguish ambiguous overloads when implicitly casting parameters

    This line works, because PowerShell correctly guesses that I want to use the constructor which takes a String, a FileMode enum, a FileAccess enum, and a FileShare enum, and implicitly casts the last three strings to the appropriate enumeration.

    $Input = New-Object System.IO.FileStream $GZFilePath, 'Open', 'Read', 'Read'

    This line fails, because PowerShell does not know if I want the constructor which takes a String and a CompressionLevel enum, or a String and a CompressionMode enum.

    $Stream = New-Object System.IO.Compression.GzipStream $Input, 'Decompress'

    But PowerShell could distinguish between the two by checking if the string is a valid name in one and…

    3 votes
    Sign in
    (thinking…)
    Sign in with: Facebook Google
    Signed in as (Sign out)

    We’ll send you updates on this idea

    survey  ·  0 comments  ·  PowerShell Engine  ·  Flag idea as inappropriate…  ·  Admin →
← Previous 1
  • Don't see your idea?

Feedback and Knowledge Base