-
Notifications
You must be signed in to change notification settings - Fork 1
/
PSOD.helpers.ps1
62 lines (50 loc) · 1.83 KB
/
PSOD.helpers.ps1
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
54
55
56
57
58
59
60
61
62
################################################################################
# Author : Antony Onipko
# Copyright : (c) 2016 Antony Onipko. All rights reserved.
################################################################################
# This work is licensed under the
# Creative Commons Attribution-ShareAlike 4.0 International License.
# To view a copy of this license, visit
# https://creativecommons.org/licenses/by-sa/4.0/
################################################################################
################################### Helpers ####################################
Function joinPath($Path1, $Path2, $Delimiter = '/') {
if (!$Path1) { $Path1 = "" }
if (!$Path2) { $Path2 = "" }
return $Path1.Replace('\','/').TrimEnd('/'),
$Path2.Replace('\','/').TrimStart('/') `
-join $Delimiter
}
################################################################################
Function newOneDriveItem {
<#
.SYNOPSIS
Creates a new PSOD.OneDriveItem object from an API response.
.EXAMPLE
New-OneDriveItem $response
.EXAMPLE
$response | New-OneDriveItem
#>
[CmdletBinding()]
[OutputType([PsObject])]
Param
(
#
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
Position=1)]
[PsObject]$ApiResponse
)
Process {
if ($ApiResponse.PsObject.Properties['value']) {
$val = $ApiResponse.value
} else {
$val = $ApiResponse
}
$val | % {
$_.PsObject.TypeNames.Insert(0, "PSOD.OneDriveItem")
Write-Output $_
}
}
}
################################################################################