Pipeline | help needed to correct my code

This topic contains 2 replies, has 3 voices, and was last updated by  Stephen Owen 2 years, 7 months ago.

  • Author
  • #22207


    Hi Team
    The following attached are my source files, all are working fine when I run them individually until like the below example...

    Get-Service DNS* | Start-Service.

    Among the attached files you can see Get-ScheduledTask and Start-ScheduledTask, all my requirement is to combine (by pipe line (|)) both Get-XXX and Start-XXX (I need vice versa) but I am in vain to change the required parameters accordingly. I am always failing in this spot. Could someone correct the Get and Start (if .ps1xml) coding and revert me.

    Attached Files info:
    1. Get-ScheduledTask – Get the scheduled tasks information on a given computer.
    2. Start-ScheduledTask – Starts the given scheduled task
    3. Format_SchTsks.ps1xml – FormatData for Get-ScheduledTask command.

  • #22213

    Tim Pringle

    Hi Vidya,

    I cannot see where you are placing output to the pipeline at the end of the process? This is typically of the format.

     $hash = @{
                outputparam =  $outputparam
            New-Object -TypeName PsObject -Property $hash

    NB I'd also normally use [Parameter()] type entries with [CmdletBinding()] also there, though it will still operate okay without.

  • #22252

    Stephen Owen

    Wow, that is some very convoluted code.

    A few things.

    [ol]{Sanitize your code. You shouldn't post code that has your customer or client name. That means remove the name of the bank!}[/ol]
    [ol]Start simply when you're trying to get pipeline input to work. I agree with Tim, I don't see anywhere that your process is outputting a powerShell object. You need to make sure that you have a line somewhere in your get-scheduledtask that outputs an object that Start-ScheduledTask will understand.[/ol]

    At some point, you need your Get-ScheduledTask to have a line like this, when you iterate through each task that matches the filter.


    I think this should go somewhere within the 'ForEach T in TaskName' script block. But the coding logic is so convoluted and I don't understand the purpose behind it, so it's hard for me to say where.

    The key takeaway is that you Start-Scheduled task only understands two parameters, ComputerName and TaskName. You need to add to both 'ValueFromPipelineByPropertyName=$true', and then make sure that Get-ScheduledTask outputs these values somewhere.

You must be logged in to reply to this topic.