Skip to content

Commit 7a5ce90

Browse files
committed
Fix indentation.
1 parent 2e0e1d5 commit 7a5ce90

File tree

4 files changed

+121
-121
lines changed

4 files changed

+121
-121
lines changed

ReST.ps1

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -14,58 +14,58 @@ $global:digestValue = ''
1414

1515
function Get-AADAuthToken([Uri] $Uri)
1616
{
17-
# NOTE: Create an azure app and update $clientId and $redirectUri below
18-
$clientId = ""
19-
$redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient"
17+
# NOTE: Create an azure app and update $clientId and $redirectUri below
18+
$clientId = ""
19+
$redirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient"
2020

21-
$authority = "https://login.microsoftonline.com/common"
22-
$resource = $Uri.GetLeftPart([System.UriPartial]::Authority);
21+
$authority = "https://login.microsoftonline.com/common"
22+
$resource = $Uri.GetLeftPart([System.UriPartial]::Authority);
2323

24-
$promptBehavior = [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always
25-
$platformParam = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList $promptBehavior
24+
$promptBehavior = [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always
25+
$platformParam = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters" -ArgumentList $promptBehavior
2626
$authenticationContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority, $False
2727
$authenticationResult = $authenticationContext.AcquireTokenAsync($resource, $clientId, $redirectUri, $platformParam).Result
2828

29-
return $authenticationResult
29+
return $authenticationResult
3030
}
3131

3232
function Set-SPOAuthenticationTicket([string] $siteUrl)
3333
{
34-
$siteUri = New-Object Uri -ArgumentList $siteUrl
34+
$siteUri = New-Object Uri -ArgumentList $siteUrl
3535

36-
$authResult = Get-AADAuthToken -Uri $siteUri
37-
if ($authResult -ne $null)
38-
{
39-
$global:accessHeader = $authResult.AccessTokenType + " " + $authResult.AccessToken
40-
}
41-
42-
if ([String]::IsNullOrEmpty($global:accessHeader))
43-
{
44-
throw 'Could not obtain authentication ticket based on provided credentials for specified site'
45-
}
36+
$authResult = Get-AADAuthToken -Uri $siteUri
37+
if ($authResult -ne $null)
38+
{
39+
$global:accessHeader = $authResult.AccessTokenType + " " + $authResult.AccessToken
40+
}
41+
42+
if ([String]::IsNullOrEmpty($global:accessHeader))
43+
{
44+
throw 'Could not obtain authentication ticket based on provided credentials for specified site'
45+
}
4646
}
4747

4848
function Build-ReSTRequest([string] $siteUrl, [string]$endpoint, [string]$method, [string]$body = $null)
4949
{
50-
$url = ([string]$siteUrl).TrimEnd("/") + "/_api/" + $endpoint
51-
$req = [System.Net.WebRequest]::Create($url)
52-
$req.Method = $method
53-
54-
[bool]$isReadOnly = (('GET','HEAD') -contains $req.Method)
55-
[bool]$isDigestRequest = $endpoint -contains 'contextinfo'
56-
57-
if ([String]::IsNullOrEmpty($body))
58-
{
59-
$req.ContentLength = 0;
60-
}
61-
else
62-
{
63-
$req.ContentLength = $body.Length
64-
$req.ContentType = "application/json"
65-
}
50+
$url = ([string]$siteUrl).TrimEnd("/") + "/_api/" + $endpoint
51+
$req = [System.Net.WebRequest]::Create($url)
52+
$req.Method = $method
53+
54+
[bool]$isReadOnly = (('GET','HEAD') -contains $req.Method)
55+
[bool]$isDigestRequest = $endpoint -contains 'contextinfo'
56+
57+
if ([String]::IsNullOrEmpty($body))
58+
{
59+
$req.ContentLength = 0;
60+
}
61+
else
62+
{
63+
$req.ContentLength = $body.Length
64+
$req.ContentType = "application/json"
65+
}
6666

67-
# set Authorization header
68-
$req.Headers.Add("Authorization", $global:accessHeader)
67+
# set Authorization header
68+
$req.Headers.Add("Authorization", $global:accessHeader)
6969

7070
if (-not $isDigestRequest)
7171
{
@@ -74,57 +74,57 @@ function Build-ReSTRequest([string] $siteUrl, [string]$endpoint, [string]$method
7474
$req.Headers.Add("X-RequestDigest", $global:digestValue)
7575
}
7676
}
77-
78-
if (-not [String]::IsNullOrEmpty($body))
79-
{
80-
$writer = New-Object System.IO.StreamWriter $req.GetRequestStream()
81-
$writer.Write($body)
82-
$writer.Close()
77+
78+
if (-not [String]::IsNullOrEmpty($body))
79+
{
80+
$writer = New-Object System.IO.StreamWriter $req.GetRequestStream()
81+
$writer.Write($body)
82+
$writer.Close()
8383
$writer.Dispose()
84-
}
85-
86-
return $req
84+
}
85+
86+
return $req
8787
}
8888

8989
function Set-DigestValue([string]$siteUrl)
9090
{
91-
$request = Build-ReSTRequest $siteUrl 'contextinfo' 'POST' $null
92-
if ($request -eq $null)
93-
{
94-
throw 'Could not obtain a request digest value based on provided credentials for specified site'
95-
}
96-
97-
try
98-
{
99-
$resp = $request.GetResponse()
100-
$reader = [System.Xml.XmlReader]::Create($resp.GetResponseStream())
101-
if ($reader.ReadToDescendant("d:FormDigestValue"))
102-
{
103-
$global:digestValue = $reader.ReadElementContentAsString()
104-
}
105-
else
106-
{
107-
throw 'Could not obtain a request digest value based on provided credentials for specified site'
108-
}
109-
}
110-
finally
111-
{
112-
if ($reader -ne $null)
113-
{
114-
$reader.Close()
115-
$reader.Dispose()
116-
}
117-
if ($resp -ne $null)
118-
{
119-
$resp.Close()
120-
$resp.Dispose()
121-
}
122-
}
91+
$request = Build-ReSTRequest $siteUrl 'contextinfo' 'POST' $null
92+
if ($request -eq $null)
93+
{
94+
throw 'Could not obtain a request digest value based on provided credentials for specified site'
95+
}
96+
97+
try
98+
{
99+
$resp = $request.GetResponse()
100+
$reader = [System.Xml.XmlReader]::Create($resp.GetResponseStream())
101+
if ($reader.ReadToDescendant("d:FormDigestValue"))
102+
{
103+
$global:digestValue = $reader.ReadElementContentAsString()
104+
}
105+
else
106+
{
107+
throw 'Could not obtain a request digest value based on provided credentials for specified site'
108+
}
109+
}
110+
finally
111+
{
112+
if ($reader -ne $null)
113+
{
114+
$reader.Close()
115+
$reader.Dispose()
116+
}
117+
if ($resp -ne $null)
118+
{
119+
$resp.Close()
120+
$resp.Dispose()
121+
}
122+
}
123123
}
124124

125125
function Post-ReSTRequest([string]$siteUrl, [string]$endpoint, [string]$body = $null)
126126
{
127-
$request = Build-ReSTRequest $siteUrl $endpoint 'POST' $body
127+
$request = Build-ReSTRequest $siteUrl $endpoint 'POST' $body
128128
$resp = $request.GetResponse()
129129
if ($resp -ne $null)
130130
{
@@ -136,7 +136,7 @@ function Post-ReSTRequest([string]$siteUrl, [string]$endpoint, [string]$body = $
136136

137137
function Patch-ReSTRequest([string]$siteUrl, [string]$endpoint, [string]$body)
138138
{
139-
$request = Build-ReSTRequest $siteUrl $endpoint 'PATCH' $body
139+
$request = Build-ReSTRequest $siteUrl $endpoint 'PATCH' $body
140140
$resp = $request.GetResponse()
141141
if ($resp -ne $null)
142142
{
@@ -148,12 +148,12 @@ function Patch-ReSTRequest([string]$siteUrl, [string]$endpoint, [string]$body)
148148

149149
function Get-ReSTRequest([string]$siteUrl, [string]$endpoint)
150150
{
151-
$request = Build-ReSTRequest $siteUrl $endpoint 'GET'
151+
$request = Build-ReSTRequest $siteUrl $endpoint 'GET'
152152
$resp = $request.GetResponse()
153153
if ($resp -ne $null)
154154
{
155155
$reader = New-Object System.IO.StreamReader $resp.GetResponseStream()
156156
$reader.ReadToEnd()
157-
$reader.Dispose()
157+
$reader.Dispose()
158158
}
159159
}

createproject.ps1

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ Set-DigestValue $siteUrl
2020
# Project parameters as JSON payload
2121
$projectid = [Guid]::NewGuid()
2222
$body = "{
23-
'parameters': {
24-
'Id': '$projectid',
25-
'Name': 'Project_$projectid',
26-
'Description': 'Created from PowerShell using REST API'
27-
}
23+
'parameters': {
24+
'Id': '$projectid',
25+
'Name': 'Project_$projectid',
26+
'Description': 'Created from PowerShell using REST API'
27+
}
2828
}"
2929

3030
# ReST request to create a project
@@ -49,13 +49,13 @@ Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/checkOut" $null
4949
# Task parameters as JSON payload
5050
$taskid = [Guid]::NewGuid()
5151
$body = "{
52-
'parameters': {
53-
'Id': '$taskid',
54-
'Name': 'Task_$taskid',
55-
'Notes': 'Created from PowerShell using REST API',
56-
'Start': '2016-01-04T08:00:00',
57-
'Duration': '5d'
58-
}
52+
'parameters': {
53+
'Id': '$taskid',
54+
'Name': 'Task_$taskid',
55+
'Notes': 'Created from PowerShell using REST API',
56+
'Start': '2016-01-04T08:00:00',
57+
'Duration': '5d'
58+
}
5959
}"
6060

6161
# ReST request to create a task
@@ -64,10 +64,10 @@ Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Tasks/Add"
6464
# Resource parameters as JSON payload
6565
$resourceid = [Guid]::NewGuid()
6666
$body = "{
67-
'parameters': {
68-
'Id': '$resourceid',
69-
'Name': 'Resource_$resourceid'
70-
}
67+
'parameters': {
68+
'Id': '$resourceid',
69+
'Name': 'Resource_$resourceid'
70+
}
7171
}"
7272

7373
# ReST request to create a local resource
@@ -76,10 +76,10 @@ Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/ProjectRes
7676
# Enterprise resource parameters as JSON payload
7777
$enterprise_resourceid = [Guid]::NewGuid()
7878
$body = "{
79-
'parameters': {
80-
'Id': '$enterprise_resourceid',
81-
'Name': 'EnterpriseResource_$enterprise_resourceid'
82-
}
79+
'parameters': {
80+
'Id': '$enterprise_resourceid',
81+
'Name': 'EnterpriseResource_$enterprise_resourceid'
82+
}
8383
}"
8484

8585
# ReST request to create an enterprise resource
@@ -90,23 +90,23 @@ Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/ProjectRes
9090

9191
# Assignment parameters as JSON payload
9292
$body = "{
93-
'parameters': {
94-
'ResourceId': '$resourceid',
95-
'TaskId': '$taskid',
96-
'Notes': 'Created from PowerShell using REST API'
97-
}
93+
'parameters': {
94+
'ResourceId': '$resourceid',
95+
'TaskId': '$taskid',
96+
'Notes': 'Created from PowerShell using REST API'
97+
}
9898
}"
9999

100100
# ReST request to create an assignment for the local resource
101101
Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Assignments/Add" $body
102102

103103
# Assignment parameters as JSON payload
104104
$body = "{
105-
'parameters': {
106-
'ResourceId': '$enterprise_resourceid',
107-
'TaskId': '$taskid',
108-
'Notes': 'Created from PowerShell using REST API'
109-
}
105+
'parameters': {
106+
'ResourceId': '$enterprise_resourceid',
107+
'TaskId': '$taskid',
108+
'Notes': 'Created from PowerShell using REST API'
109+
}
110110
}"
111111

112112
# ReST request to create an assignment for the enterprise resource

updateproject.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ param
1212
$projectId = $(throw "projectId parameter is required"),
1313
$taskId,
1414
$resourceId,
15-
$assignmentId
15+
$assignmentId
1616
)
1717
# Load ReST helper methods
1818
. .\ReST.ps1
@@ -31,22 +31,22 @@ Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft" $body
3131
# ReST request to update the task duration
3232
if (-not [String]::IsNullOrEmpty($taskId))
3333
{
34-
$body = "{'Duration':'10d'}"
35-
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Tasks('$taskId')" $body
34+
$body = "{'Duration':'10d'}"
35+
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Tasks('$taskId')" $body
3636
}
3737

3838
# ReST request to update the resource rate
3939
if (-not [String]::IsNullOrEmpty($resourceId))
4040
{
41-
$body = "{'StandardRate':'100'}"
42-
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/ProjectResources('$resourceId')" $body
41+
$body = "{'StandardRate':'100'}"
42+
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/ProjectResources('$resourceId')" $body
4343
}
4444

4545
# ReST request to update the assignment completion percent
4646
if (-not [String]::IsNullOrEmpty($assignmentId))
4747
{
48-
$body = "{'PercentWorkComplete':'50'}"
49-
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Assignments('$assignmentId')" $body
48+
$body = "{'PercentWorkComplete':'50'}"
49+
Patch-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/Draft/Assignments('$assignmentId')" $body
5050
}
5151

5252
# ReST request to publish and check-in the project

updateprojectcustomfieldvalues.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ param
1212
$projectId = $(throw "projectId parameter is required"),
1313
$customFieldId = $(throw "customFieldId parameter is required"),
1414
$lookupEntryId, #use this parameter for custom fields associated with a lookup table
15-
$customFieldValue #use this parameter for non-lookup custom fields
15+
$customFieldValue #use this parameter for non-lookup custom fields
1616
)
1717
# Load ReST helper methods
1818
. .\ReST.ps1
@@ -29,7 +29,7 @@ Post-ReSTRequest $SiteUrl "ProjectServer/Projects('$projectid')/checkOut" $null
2929
$customFieldInternalName = ([xml] (Get-ReSTRequest $siteUrl "ProjectServer/CustomFields('$customFieldId')")).entry.content.properties.InternalName
3030
if (-not [String]::IsNullOrEmpty($lookupEntryId))
3131
{
32-
$customFieldValue = ([xml] (Get-ReSTRequest $siteUrl "ProjectServer/CustomFields('$customFieldId')/LookupEntries('$lookupEntryId')")).entry.content.properties.InternalName
32+
$customFieldValue = ([xml] (Get-ReSTRequest $siteUrl "ProjectServer/CustomFields('$customFieldId')/LookupEntries('$lookupEntryId')")).entry.content.properties.InternalName
3333
}
3434
# ReST request to update the project custom field (see http://msdn.microsoft.com/en-us/library/hh642428(v=office.12).aspx for parameter information)
3535
$body = "{'customFieldDictionary':[{'Key':'$customFieldInternalName','Value':'$customFieldValue', 'ValueType':'Edm.String'}]}"

0 commit comments

Comments
 (0)