Gets Octopus Tasks resources.

   This cmdlet can be used to track the status of tasks such as Health checks, Backups, Deployments, etc. See parameter "Name" to see all the kind of tasks available.
   Long description
   Get-OctopusTask Name Backup

   Get all the Backup tasks of the server
   Get-OctopusTask -name Health -status failed -After (Get-date).adddays(-7)

   Get all the Health check tasks that failed over the past 7 days
   Get-OctopusTask -TaskID "ServerTAsks-1234"

   Get the server task with the id "ServerTasks-1234"
   Get-OctopusTask -Name Backup -After 01/01/2015

   Get all the Backup tasks 01/01/2015
   Github project:
   QA and Cmdlet request:

function Get-OctopusTask
        # ID of task you want to get
        [parameter(ParameterSetName = 'TaskId')]
        # Name of the task. Accepted values are: 'Backup','Delete','Health','Retention','Deploy','Upgrade','AdhocScript','TestEmail'
        [String[]]$Name = '*',

        # Document related to this task.
        [string]$ResourceID = '*',

        # Status of the task.
        [string[]]$State = '*',

        # Before date
        [System.DateTimeOffset]$Before = [System.DateTimeOffset]::MaxValue,
        # After date
        [System.DateTimeOffset]$After = [System.DateTimeOffset]::MinValue

        $c = New-OctopusConnection
        $list = @()
            Write-Verbose "[$($MyInvocation.MyCommand)] Getting tasks by ID"

            $tasks = @()

            foreach($t in $TaskID){
                Write-Verbose "[$($MyInvocation.MyCommand)] Getting task id: $t"
                $task = $c.repository.Tasks.Get($t)
                If($task -eq $null){
                    Write-Error "No tasks found with ID $t"
                else {$tasks += $task}

        elseif(($Name -ne '*') -or ($ResourceID -ne '*') -or ($State -ne '*') -or ($Before -ne [System.DateTimeOffset]::MaxValue) -or ($After -ne [System.DateTimeOffset]::MinValue)) {
            Write-Verbose "[$($MyInvocation.MyCommand)] Getting task by: `nName: $name`nResourceID: $resourceid`nState: $state`nBefore: $before`nAfter: $after"
            $tasks = $c.repository.Tasks.FindMany({param($t) if( (($ -like $Name) -or ($ -in $name) ) -and (($t.state -like $State) -or ($t.state -in $State) )-and (($t.Arguments.values -contains $ResourceID) -or ($t.Arguments -like $ResourceID)) -and ($t.StartTime -ge $After) -and ($t.LastupdatedTime -le $Before)
            ) {$true}})        

            Write-Verbose "[$($MyInvocation.MyCommand)] Getting all tasks"
            $tasks = $c.repository.Tasks.FindAll()
        Write-Verbose "[$($MyInvocation.MyCommand)] Tasks found: $($Tasks.count)"

        $list += $tasks       
        If($list.count -eq 0){
            $list = $null
        return $List