Public/Update-Task.ps1
function Update-Task { param( [string]$ChannelId, [string]$EntityId, [string]$GroupId, [string]$TeamId, [string]$Domain = "teams-stag.appvity.com", [string]$t, [string]$ProjectId, $Id, $BodyObject, [string]$Title, [string]$AssignedTo, [string]$Attachments, [string]$Body, [string]$Bucket, [string]$Complete, [string]$CompletedDate, [string]$DueDate, [string]$Effort, [string]$Name, [string]$Owner, [string]$Phase, [string]$Priority, [string]$RelatedItems, [string]$StartDate, [string]$Status, [string]$Source, [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($validate) { $validate = $validate.TrimStart(',').TrimStart() + ' is require' Write-Host $validate -F Red return } #cookie $cookie = $Cookie if(!$cookie){ $cookie = Get-GraphOauthCookie #Write-Host '-------------cookie------------------' #Write-Host $cookie } #get task detail $taskDetail = Get-TaskDetails -Url $Url -t $t -Id $Id $BucketName = '' $PhaseName = '' if(!$BodyObject) { if(!$Title) {$Title = $taskDetail.name} if(!$AssignedTo) {$AssignedTo = $taskDetail.assignedTo} if(!$Attachments) {$Attachments = $taskDetail.attachments} if(!$Body) {$Body = $taskDetail.body} if(!$Bucket) {$Bucket = $taskDetail.bucket} if(!$Complete) {$Complete = $taskDetail.complete} if(!$CompletedDate) {$CompletedDate = $taskDetail.completedDate} if(!$DueDate) {$DueDate = $taskDetail.dueDate} if(!$Effort) {$Effort = $taskDetail.effort} if(!$Owner) {$Owner = $taskDetail.owner} if(!$Phase) {$Phase = $taskDetail.phase} if(!$Priority) {$Priority = $taskDetail.priority} if(!$RelatedItems) {$RelatedItems = $taskDetail.relatedItems} if(!$StartDate) {$StartDate = $taskDetail.startDate} if(!$Status) {$Status = $taskDetail.status} if(!$Source) {$Source = $taskDetail.source} } if($BodyObject) { $object = $BodyObject | ConvertFrom-Json if($object.Title) {$Title = $object.Title} if($object.AssignedTo) {$AssignedTo = $object.AssignedTo} if($object.Attachments) {$Attachments = $object.Attachments} if($object.Body) {$Body = $object.Body} if($object.Bucket) {$Bucket = $object.Bucket} if($object.Complete) {$Complete = $object.Complete} if($object.CompletedDate) {$CompletedDate = $object.CompletedDate} if($object.DueDate) {$DueDate = $object.DueDate} if($object.Effort) {$Effort = $object.Effort} if($object.Name) {$Name = $object.Name} if($object.Owner) {$Owner = $object.Owner} if($object.Phase) {$Phase = $object.Phase} if($object.Priority) {$Priority = $object.Priority} if($object.RelatedItems) {$RelatedItems = $object.RelatedItems} if($object.StartDate) {$StartDate = $object.StartDate} if($object.Status) {$Status = $object.Status} if($object.Source) {$Source = $object.Source} } <# #validation if(!$Title) { Write-Host "Title not found." -F red return } if(!$Source) { Write-Host "Source not found." -F red return } if(!$Priority) { Write-Host "Priority not found." -F red return } if(!$Status) { Write-Host "Status not found." -F red return } #> $Arr = @{ name = $Title status = $Status body = $Body source = $Source priority = $Priority startDate = $StartDate dueDate = $DueDate attachments = $Attachments bucket = $Bucket bucketName = $BucketName complete = $Complete completedDate = $CompletedDate effort = $Effort owner = $Owner phase = $Phase phaseName = $PhaseName projectId = '5d15bd83d9570032862cafe6' relatedItems = @() 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(' + $Id + ')' $Params = @{ Uri = $Url Method = 'PATCH' Headers = $hd Body = $Arr } try { Invoke-WebRequest @Params -WebSession $session } catch{ Write-Error $_.Exception.Message } } |