Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-AsJob parameter not wwork in PowerShell Docker #792

Open
5 tasks done
ShaiViente opened this issue Feb 10, 2024 · 0 comments
Open
5 tasks done

-AsJob parameter not wwork in PowerShell Docker #792

ShaiViente opened this issue Feb 10, 2024 · 0 comments

Comments

@ShaiViente
Copy link

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest image.
  • Search the existing issues.
  • Verified that this is not a Known Issue
  • Verified this is not an issues in the underlying windows container that should be reported to Windows Feedback Hub

Steps to reproduce

I'm trying to run the following script - which will show me the fastest way my network status (ping, TTL, DNS)
The script is attached here:
$segment = "192.168.0"
1..254 |%{Test-Connection -Count 1 -ComputerName "$segment.$_" -AsJob}
$Results=Get-Job | Receive-Job -Wait | select @{N="IP";E={$_.Address}},@{N="ping";E={[bool]$_.ResponseTimeToLive}},@{N="TTL";E={$_.ResponseTimeToLive}},@{N="DNS";E={[System.Net.Dns]::GetHostByAddress($_.Address).Hostname}}
``

Of course I will use the Test-Connection command with the quick option -AsJob
It doesn't work because this Powershell version doesn't have -AsJob as you can see in the image:

asjob_pwsh

Why? Is there an option to run regular Powershell on Docker?
Instead, I ended up doing everything with Start-Job
But it comes out significantly slow. Instead within a second - within a minute
Would appreciate help!

Expected behavior

PS C:\> Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command                  
--     ----            -------------   -----         -----------     --------             -------                  
3753   Job3753         WmiJob          Running       True            .                    Test-Connection

Actual behavior

PS /> Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
Test-Connection: A parameter cannot be found that matches parameter name 'AsJob'.

Error details

PS /> Get-Error

Exception             :
    Type              : System.Management.Automation.ParameterBindingException
    Message           : A parameter cannot be found that matches parameter name 'AsJob'.
    ParameterName     : AsJob
    ErrorId           : NamedParameterNotFound
    Line              : 1
    Offset            : 61
    CommandInvocation :
        MyCommand        : Test-Connection
        BoundParameters  :
            Comparer : System.OrdinalIgnoreCaseComparer
            Count    : 2
            Keys     :
                Length : 5

                Length : 10
            Values   :


                Length      : 1
                LongLength  : 1
                Rank        : 1
                SyncRoot    :
                    Length : 13
                IsFixedSize : True
                Count       : 1
            SyncRoot :
                Comparer : System.OrdinalIgnoreCaseComparer
                Count    : 2
                Keys     :
                    Length : 5

                    Length : 10
                Values   :


                    Length      : 1
                    LongLength  : 1
                    Rank        : 1
                    SyncRoot    :
                        Length : 13
                    IsFixedSize : True
                    Count       : 1
                SyncRoot :
                    Comparer : System.OrdinalIgnoreCaseComparer
                    Count    : 2
                    Keys     :
                        Length : 5

                        Length : 10
                    Values   :


                        Length      : 1
                        LongLength  : 1
                        Rank        : 1
                        SyncRoot    :
                            Length : 13
                        IsFixedSize : True
                        Count       : 1
                    SyncRoot :
                        Comparer : System.OrdinalIgnoreCaseComparer
                        Count    : 2
                        Keys     :
                            Length : 5

                            Length : 10
                        Values   :


                            Length      : 1
                            LongLength  : 1
                            Rank        : 1
                            SyncRoot    :
                                Length : 13
                            IsFixedSize : True
                            Count       : 1
                        SyncRoot :
                            Comparer : System.OrdinalIgnoreCaseComparer
                            Count    : 2
                            Keys     :
                                Length : 5

                                Length : 10
                            Values   :


                                Length      : 1
                                LongLength  : 1
                                Rank        : 1
                                SyncRoot    :
                                    Length : 13
                                IsFixedSize : True
                                Count       : 1
                            SyncRoot :
                                Comparer : System.OrdinalIgnoreCaseComparer
                                Count    : 2
                                Keys     :
                                    Length : 5

                                    Length : 10
                                Values   :


                                    Length      : 1
                                    LongLength  : 1
                                    Rank        : 1
                                    SyncRoot    : …
                                    IsFixedSize : True
                                    Count       : 1
                                SyncRoot :
                                    Comparer : System.OrdinalIgnoreCaseComparer
                                    Count    : 2
                                    Keys     : …
                                    Values   : …
                                    SyncRoot : …
        ScriptLineNumber : 1
        OffsetInLine     : 6
        HistoryId        : 2
        Line             : $1 = Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
        Statement        : Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
        PositionMessage  : At line:1 char:6
                           + $1 = Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
                           +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        InvocationName   : Test-Connection
        PipelineLength   : 1
        PipelinePosition : 1
    ErrorRecord       :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : A parameter cannot be found that matches parameter name 'AsJob'.
            HResult : -2146233087
        CategoryInfo          : InvalidArgument: (:) [Test-Connection], ParentContainsErrorRecordException
        FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.TestConnectionCommand
        InvocationInfo        :
            MyCommand        : Test-Connection
            ScriptLineNumber : 1
            OffsetInLine     : 61
            HistoryId        : 2
            Line             : $1 = Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
            Statement        : -AsJob
            PositionMessage  : At line:1 char:61
                               + $1 = Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
                               +                                                             ~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite        :
        Name          : VerifyArgumentsProcessed
        DeclaringType : System.Management.Automation.CmdletParameterBinderController, System.Management.Automation, Version=7.4.1.500, Culture=neutral, PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Data              : System.Collections.ListDictionaryInternal
    Source            : System.Management.Automation
    HResult           : -2146233087
    StackTrace        :
   at System.Management.Automation.CmdletParameterBinderController.VerifyArgumentsProcessed(ParameterBindingException originalBindingException)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
   at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
   at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][]
commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidArgument: (:) [Test-Connection], ParameterBindingException
FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.TestConnectionCommand
InvocationInfo        :
    MyCommand        : Test-Connection
    ScriptLineNumber : 1
    OffsetInLine     : 61
    HistoryId        : 2
    Line             : $1 = Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
    Statement        : -AsJob
    PositionMessage  : At line:1 char:61
                       + $1 = Test-Connection -Count 1 -ComputerName "192.168.0.128" -AsJob
                       +                                                             ~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

docker pull mcr.microsoft.com/powershell:latest

Visuals

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant