User defined operators and parallel execution

Hi, folks! I'm looking for a way to create custom operators such as  -any or -selectmany and so on. Not sure that it's possible to do with PowerShell scripts so... Maybe somebody faced with this or have an experience for creating custom operators? Can you explain me how to do this?

My second question is how to use System.Threading.Tasks.Parallel in my scripts? Should I create a runspace to use it and where I can to see examples?

Thank for advance!

  • What are you trying to accomplish by this effort.

    These sorts of things are just switch parameters a common the in PoSH, you can see this by looking at the code of cmdlet, functions.

        Function MyNew-Function
        {
            [CmdletBinding()]
            [Alias('EnterAliasName')]

            Param
            (
                [switch]$Any,
                [switch]$SelectMany
            )

            # Code begins here

        }

        MyNew-Function -Any
        MyNew-Function -SelectMany

    As for ...how to use System.Threading.Tasks.Parallel 

    That is all laid out in the .Net api documentation on MSDN and TechNet. You can use any .Net library/namespace in PoSH.

    There are a lot of docs on Parrallel process using PoSH on the same resources and many others web blogs, yourtube vid, MS Channel9, Microsoft Virtual Academy, etc., with samples on MS Powershellgallery.com and the MS scripting guys blogs and more. Just use your facorite search engine to find them. 'powershell parrallel processing'

    Example hits:

    Parallel processing with PowerShell
    'blogs.technet.microsoft.com/uktechnet/2016/06/20/parallel-processing-with-powershell'

    Invoke-Parallel - Parallel PowerShell

    This function will take in a script or scriptblock, and run it against specified objects(s) in parallel. It uses runspaces, as there are many situations where jobs or PSRemoting are not appropriate.
    'gallery.technet.microsoft.com/scriptcenter/Run-Parallel-Parallel-377fd430


    PowerShell / Invoke-Parallel.ps1
    'github.com/RamblingCookieMonster/PowerShell/blob/master/Invoke-Parallel.ps1'


    Multi threading - Powershell to Run Commands in Parallel

    Reduce remote powershell execution time using multi threading in powershell v2 We can use multi threading in powershell v2 using start-job command which will execute the script block on multiple servers parallely rather than going one by one. In powershell v3 there is additional

    'gallery.technet.microsoft.com/scriptcenter/Multi-threading-Powershell-d2c0e2e5'