-
Notifications
You must be signed in to change notification settings - Fork 1
/
Func_Move-OneDriveItem.ps1
85 lines (70 loc) · 2.74 KB
/
Func_Move-OneDriveItem.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
################################################################################
# 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/
################################################################################
Function Move-OneDriveItem {
<#
.SYNOPSIS
Move a OneDrive item from one parent to another.
.EXAMPLE
"Documents/file.pdf" | Move-OneDriveItem "destination/directory"
.EXAMPLE
Move-OneDriveItem -ItemID "85B75A4CE0397EE!1492" -destination "destination/directory"
.EXAMPLE
Move-OneDriveItem "Documents/DirToMove" "new/parent"
#>
[CmdletBinding(DefaultParameterSetName='Item Path')]
[Alias('odmv', 'odmove')]
[OutputType([PsObject])]
Param
(
# API resource path.
[Parameter(Mandatory=$False,
Position=1,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
ParameterSetName='Item Path')]
[Alias('ApiUrl', 'Resource')]
[string]$Path,
# API item ID.
[Parameter(Mandatory=$True,
Position=1,
ValueFromPipelineByPropertyName=$True,
ParameterSetName='Item ID')]
[Alias('id')]
[string]$ItemId,
# The path to the destination directory / file.
[Parameter(Mandatory=$True,
Position=2)]
[string]$Destination
)
Process {
if ($ItemId) {
$p = joinPath $PSOD.drive.itemRoot $ItemId
} else {
$p = joinPath $PSOD.drive.pathRoot $Path
}
Write-Verbose "Sending request to '$p'"
$body = [ordered]@{
parentReference = @{
path = "/" + (joinPath $PSOD.drive.pathRoot $Destination)
}
} | ConvertTo-Json
Write-Verbose "Request body:`n$body"
$rsp = Invoke-OneDriveApiCall -Path $p `
-Method PATCH `
-Body $body `
-AdditionalRequestHeaders @{
Prefer = "respond-async"
}
if ($rsp) {
Write-Output $rsp | newOneDriveItem
}
}
}
Export-ModuleMember -Function 'Move-OneDriveItem' -Alias 'odmv', 'odmove'