-
Notifications
You must be signed in to change notification settings - Fork 0
/
Upload-ShareFile.ps1
94 lines (75 loc) · 2.63 KB
/
Upload-ShareFile.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
86
87
88
89
90
91
92
93
94
<#
.SYNOPSIS
Upload one or more file or directories to a destination on ShareFile.
.PARAMETER Files
A collection of files and/or directories to upload.
Directories are uploaded as-is, preserving their name and entire structure to DestinationDirectory.
Individual files are uploaded directly to DestinationDirectory, without preserving their parent
directories.
.PARAMETER Destination
The directory name on ShareFile where files will be uploaded to.
.PARAMETER Exclude
A collection of strings used to exclude files. Supports typical powershell wildcards.
.PARAMETER ShareParentFolderLink
If specified, the Share link that is created will point directly to DestinationDirectory,
instead of to the individually uploaded files. This means the directory structure will be
displayed in the share.
.PARAMETER ExpirationDate
The expiration date of the created Share. The default of [datetime]::MaxValue means
the Share does not expire.
.PARAMETER Timeout
Http response timeout in milliseconds.
#>
[CmdletBinding(SupportsShouldProcess=$True)]
param(
[Parameter(Mandatory=$True)]
[string] $ClientID,
[Parameter(Mandatory=$True)]
[string] $ClientSecret,
[Parameter(Mandatory=$True)]
[string] $Username,
[Parameter(Mandatory=$True)]
[string] $Password,
[Parameter(Mandatory=$True)]
[string] $Subdomain,
[Parameter(Mandatory=$true)]
$Files,
[Parameter(Mandatory=$true)]
[string] $DestinationDirectory,
[string[]] $Exclude,
[switch] $ShareParentFolderLink,
[datetime] $ExpirationDate = [datetime]::MaxValue,
[string] $ApplicationControlPlane = "sharefile.com",
[string] $Endpoint = "https://secure.sf-api.com/sf/v3/",
[int] $Timeout = 120000
)
$UtilsScript = Join-Path $PSScriptRoot ShareFile-Utils.ps1
. $UtilsScript
try
{
$ShareFileClient = Connect-ShareFileClient -ClientID $ClientID -ClientSecret $ClientSecret -Username $Username -Password $Password -Subdomain $Subdomain -ApplicationControlPlane $ApplicationControlPlane -Endpoint $Endpoint
$CopyArgs = @{
'-ShareFileClient'=$ShareFileClient;
'-DestinationDirectory'=$DestinationDirectory;
'-ExpirationDate'=$ExpirationDate;
'-Files'=$Files
}
if ($Exclude)
{
$CopyArgs.Add('-Exclude', $Exclude)
}
if ($ShareParentFolderLink)
{
$CopyArgs.Add('-ShareParentFolderLink', $ShareParentFolderLink)
}
if ($Timeout)
{
$CopyArgs.Add('-Timeout', $Timeout)
}
Copy-ToShareFile @CopyArgs
}
catch [System.AggregateException]
{
$_.Exception.ToString() | Out-Host
throw
}