forked from OfficeDev/Project-REST-Basic-Operations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateproject.ps1
More file actions
54 lines (44 loc) · 1.71 KB
/
Copy pathupdateproject.ps1
File metadata and controls
54 lines (44 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<#
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
See LICENSE in the project root for license information.
#>
# Updates a Project using ReST API
param
(
# SharepointOnline project site collection URL
$SiteUrl = $(throw "SiteUrl parameter is required"),
$projectId = $(throw "projectId parameter is required"),
$taskId,
$resourceId,
$assignmentId
)
# Load ReST helper methods
. .\ReST.ps1
# Set up the request authentication
Set-SPOAuthenticationTicket $siteUrl
Set-DigestValue $siteUrl
# ReST request to check out the project
Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/checkOut" $null
# ReST request to update the project description
$body = "{'Description':'Updated from PowerShell using REST API'}"
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft" $body
# ReST request to update the task duration
if (-not [String]::IsNullOrEmpty($taskId))
{
$body = "{'Duration':'10d'}"
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Tasks('$taskId')" $body
}
# ReST request to update the resource rate
if (-not [String]::IsNullOrEmpty($resourceId))
{
$body = "{'StandardRate':'100'}"
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/ProjectResources('$resourceId')" $body
}
# ReST request to update the assignment completion percent
if (-not [String]::IsNullOrEmpty($assignmentId))
{
$body = "{'PercentWorkComplete':'50'}"
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Assignments('$assignmentId')" $body
}
# ReST request to publish and check-in the project
Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/publish(true)" $null