Skip to content

get-winevent inside invoke-command can't handle arrays inside filterhashtable #13108

Closed

Description

@jszabo98

Steps to reproduce

# elevated prompt
start-service winrm
invoke-command localhost { get-winevent @{logname = 'application'; level = 1,2,3} }  

Expected behavior

# many events

Actual behavior

Get-WinEvent: No events were found that match the specified selection criteria.

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.1
PSEdition                      Core
GitCommitId                    7.0.1
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Workaround, define an array variable first inside the scriptblock. Note that passing in an array as a param() to invoke-command is notoriously difficult.

invoke-command localhost { $levels = 1,2,3; get-winevent @{logname = 'application'; level = $levels} }

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Jul 5, 2020
  2. iSazonov commented on Jul 6, 2020

    @iSazonov
    Collaborator

    Can you confirm that you use PS7 remote point (not Windows PowerShell remote point)?

  3. jszabo98 commented on Jul 6, 2020

    @jszabo98
    Author

    No, as is likely, the remote endpoint is PS 5. How do you enable a PS 7 endpoint? Running enable-psremote in PS 7 doesn't seem to do anything. Get-PSSessionConfiguration doesn't return anything. (Not working in win10 2004, crashing)

    # windows 10 2004
    Enable-PSRemoting
    
    WARNING: PowerShell remoting has been enabled only for PowerShell 6+ configurations and does not affect Windows
    PowerShell remoting configurations. Run this cmdlet in Windows PowerShell to affect all PowerShell remoting 
    configurations.  WinRM is already set up to receive requests on this computer.
    Set-WSManQuickConfig:
    Line |
     121 |                  Set-WSManQuickConfig -force
         |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
         | <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113" 
    Machine="localhost"><f:Message><f:ProviderFault provider="Config provider" 
    path="%systemroot%\system32\WsmSvc.dll"><f:WSManFault 
    xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113" Machine="mycomputer.com">
    <f:Message>WinRM firewall exception will not work since one of the network connection types on this machine is set to
    Public. Change the network connection type to either Domain or Private and try again. </f:Message></f:WSManFault>
    </f:ProviderFault></f:Message></f:WSManFault>
    
    Get-PSSessionConfiguration # no output

    Remote powershell 7 confirmed in windows 10 1809:

    Enable-PSRemoting
    
    WARNING: PowerShell remoting has been enabled only for PowerShell 6+ configurations and does not affect Windows 
    PowerShell remoting configurations. Run this cmdlet in Windows PowerShell to affect all PowerShell remoting configurations.
    WinRM is already set up to receive requests on this computer.
    WinRM is already set up for remote management on this computer.
    
    
    Get-PSSessionConfiguration  # PS 5 remotes not shown
    
    Name          : PowerShell.7
    PSVersion     : 7.0
    StartupScript :
    RunAsUser     :
    Permission    : NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote
                    Management Users AccessAllowed
    
    Name          : PowerShell.7.0.2
    PSVersion     : 7.0
    StartupScript :
    RunAsUser     :
    Permission    : NT AUTHORITY\INTERACTIVE AccessAllowed, BUILTIN\Administrators AccessAllowed, BUILTIN\Remote
                    Management Users AccessAllowed
    
    
    invoke-command localhost { get-winevent @{logname = 'application'; level = 1,2,3} } -ConfigurationName powershell.7
    
    Get-WinEvent: No events were found that match the specified selection criteria.
    
    
    # array test, only first element still returned
    icm localhost { param($levels) $levels } -args 1,2,3 -ConfigurationName powershell.7
    
    1

    Windows 10 1903/1909 shrug (works as domain admin not local admin)

    invoke-command localhost { get-winevent @{logname = 'application'; level = 1,2,3} } -ConfigurationName powershell.7
    
    OpenError: [localhost] Connecting to remote server localhost failed with the following error message : Access is denied. For
    more information, see the about_Remote_Troubleshooting Help topic.
  4. iSazonov commented on Jul 6, 2020

    @iSazonov
    Collaborator

    Paul Higinbotham (@PaulHigin) Could you please comment the issue?

  5. PaulHigin commented on Jul 6, 2020

    @PaulHigin
    Contributor

    This is not a regression since it can be repro'd in WindowsPowerShell 5.1. This looks like another bug in the 'GetPowerShell' method that tries to convert script text into equivalent PowerShell command/parameters. The above workaround works because it causes the conversion to fail and the script text is sent to the target computer as is. A fix for this may involve detecting a hash table parameter argument like this and failing the conversion.

  6. added
    Issue-BugIssue has been identified as a bug in the product
    and removed
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Jul 6, 2020
  7. daxian-dbw commented on Jul 6, 2020

    @daxian-dbw
    Member

    It looks GetPowerShell method is working as expected, but the problem lies in the serialization/deserialization layer -- the object[] (1,2,3) got deserialized into an ArrayList on the remote side, and hence Get-WinEvent couldn't understand the filter hashtable.

    PS> $s = New-PSSession .
    PS> Enter-PSSession $s
    [localhost]: PS> function bar { param([hashtable] $h) $h; $type = $h['level'].GetType().FullName; "`nType of level's value: $type" }
    [localhost]: PS> exit
    PS> invoke-command $s { bar @{logname = 'application'; level = 1,2,3} }
    
    Name                           Value
    ----                           -----
    level                          {1, 2, 3}
    logname                        application
    
    Type of level's value: System.Collections.ArrayList

    If you use ArrayList locally, you will get the same error.

    PS> $al = [System.Collections.ArrayList]::new()
    PS> $al.Add(1) > $null
    PS> $al.Add(2) > $null
    PS> $al.Add(3) > $null
    PS> Get-WinEvent @{ logname = 'application'; level = $al}
    Get-WinEvent: No events were found that match the specified selection criteria.
    

    I'm not sure if this can be fixed at all since it's in the serialization/deserialization layer. Paul Higinbotham (@PaulHigin) any thoughts?

  8. PaulHigin commented on Jul 6, 2020

    @PaulHigin
    Contributor

    I would argue that GetPowerShell is not working correctly, if its conversion to command/parameters fails, even if the failure is in the serialization system. I doubt we can safely change serialization behavior so I feel the best fix is to not perform conversion for hashtable argument cases, if they can't be transferred correctly.

  9. daxian-dbw commented on Jul 6, 2020

    @daxian-dbw
    Member

    The failure can happen in a different form, where GetPowerShell is not involved:

    PS:45> Invoke-Command $s { param($h) $h.GetType(); Get-WinEvent $h } -ArgumentList @{logname = 'application'; level = 1,2,3}
    
    IsPublic IsSerial Name                                     BaseType                                 PSComputerName
    -------- -------- ----                                     --------                                 --------------
    True     True     Hashtable                                System.Object                            localhost
    Get-WinEvent: No events were found that match the specified selection criteria.
    
  10. PaulHigin commented on Jul 6, 2020

    @PaulHigin
    Contributor

    Yes, definitely this is broken and we should look at fixing it if possible. But the script version works just fine and is probably much more common. I feel we are compounding the problem by gratuitously converting the working script to a broken command form. We may be able to fix it in the serialization system, but I am a little worried about making changes there. But I agree that if it can be fixed there, that would be ideal.

  11. SteveL-MSFT commented on Jul 8, 2020

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee discussed this in relation to another issue, we agreed that remoting should not be using GetPowerShell and instead should be passing the scriptblock as text to be handled by the target

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  14. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  15. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-BugIssue has been identified as a bug in the productResolution-No ActivityIssue has had no activity for 6 months or moreWG-RemotingPSRP issues with any transport layer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions