Public/Clone-Task.ps1

function Clone-Task {
    param( 
        [string]$ChannelId,
        [string]$EntityId,
        [string]$GroupId,
        [string]$TeamId,
        [string]$Domain = "teams-stag.appvity.com",
        $TaskId,
        [string]$Cookie
    )

    $validate = ''
    if(!$Domain){
        $validate = $validate + ', Domain'
    }
    if(!$ChannelId){
        $validate = $validate + ', ChannelId'
    }
    <#
    if(!$EntityId){
        $validate = $validate + ', EntityId'
    }
    if(!$GroupId){
        $validate = $validate + ', GroupId'
    }
    #>

    if(!$TeamId){
        $validate = $validate + ', TeamId'
    }
    if(!$TaskId){
        $validate = $validate + ', TaskId'
    }
    if($validate) {
        $validate = $validate.TrimStart(',').TrimStart() + ' is require'
        Write-Host $validate -F Red
        return
    }

    #cookie
    $cookie = $Cookie
    if(!$cookie){
        $cookie = Get-GraphOauthCookie -BaseURL $Domain
        #Write-Host '-------------cookie------------------'
        #Write-Host $cookie
    }

    #get task detail
    $taskDetail = Get-TaskDetails -ChannelId $ChannelId -TeamId $TeamId -Domain $Domain -TaskId $TaskId -Cookie $Cookie

    if($taskDetail) {
        $Arr = @{
            name = $taskDetail.name
            status = $taskDetail.status
            body = $taskDetail.body
            source = $taskDetail.source
            priority = $taskDetail.priority
            startDate = $taskDetail.startDate
            dueDate = $taskDetail.dueDate
            attachments = $taskDetail.attachments
            bucket = $taskDetail.bucket
            bucketName = $taskDetail.bucketName
            complete = $taskDetail.complete
            completedDate = $taskDetail.completedDate
            effort = $taskDetail.effort
            owner = $taskDetail.owner
            phase = $taskDetail.phase
            phaseName = $taskDetail.phaseName
            projectId = $taskDetail.projectId
            relatedItems = $taskDetail.relatedItems
            assignedTo = $taskDetail.assignedTo
        } | ConvertTo-Json
    }

    #header
    $hd = New-Object 'System.Collections.Generic.Dictionary[String,String]'
    $hd.Add("x-appvity-channelId",$ChannelId)
    $hd.Add("x-appvity-entityId",$EntityId)
    $hd.Add("x-appvity-groupId",$GroupId)
    $hd.Add("x-appvity-teamid",$TeamId)
    $hd.Add("Content-Type","application/json")

    #session
    $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
    $ck = New-Object System.Net.Cookie 
    $ck.Name = "graphNodeCookie"
    $ck.Value = $cookie
    $ck.Path = "/"
    $ck.Domain = $Domain
    $session.Cookies.Add($ck);

    $Url = 'https://' + $Domain.TrimEnd('/') + '/odata/tasks'

    $Params = @{
        Uri = $Url
        Method = 'POST'
        Headers = $hd
        Body = $Arr
    }

    try {
        Invoke-WebRequest @Params -WebSession $session
    }
    catch{
        Write-Error $_.Exception.Message
    }
}