Author Posts

January 28, 2015 at 2:12 am

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.

January 28, 2015 at 3:51 am

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.

January 29, 2015 at 6:57 am

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.

[pscustomobject]@{ComputerName=$ComputerName;TaskName=$t.Name}

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.