10 |
11 |
12 |
13 | |
14 |
15 | Download
16 | Download the latest release here
17 | |
18 |
19 |
20 |
21 |
22 | |
23 |
24 | System Requirements
25 | The PowerShell SDK requires PowerShell 4.x, .NET 4.8, and the WebView2 runtime.
26 | |
27 |
28 |
29 |
30 |
31 | |
32 |
33 | Getting Started
34 | Click here if you are just getting started for a list of common operations. We will walk you through your first time using the SDK using some basic operations.
35 | |
36 |
37 |
38 |
39 |
40 | |
41 |
42 | Sample Scripts
43 | Here you will find some example scripts that are commonly used by customers.
44 | |
45 |
46 |
47 |
48 |
49 | |
50 |
51 | Scheduling Scripts
52 | Found a great script that you want to run automatically on a regular basis? Check here for more information on how to schedule scripts.
53 | |
54 |
55 |
56 |
57 |
58 | |
59 |
60 | Syncing Files
61 | Coming from the SFCLI tool? This section contains details on how you can use the PowerShell SDK to do the same type of activities.
62 | |
63 |
64 |
65 |
66 |
67 | |
68 |
69 | License
70 | All code is licensed under the MIT
71 | License
72 | |
73 |
74 |
75 |
76 |
77 | To follow us on the ShareFile blog, check here:
78 | https://www.sharefile.com/blogs
79 |
--------------------------------------------------------------------------------
/Samples/StorageReport.ps1:
--------------------------------------------------------------------------------
1 | Add-PSSnapin ShareFile
2 |
3 | ################################################################################
4 | # StorageReport.ps1
5 | #
6 | # This script will list all files that are in any shared folder or a user home
7 | # folder in a custom .csv file.
8 | #
9 | # Notes:
10 | # - Script should be run as a super user or user who has access to all shared
11 | # folders and all home folders
12 |
13 | #Run the following interactively to create a login token that can be used by Get-SfClient in unattended scripts
14 | #$sfClient = New-SfClient -Name ((Join-Path $env:USERPROFILE "Documents") + "\YourSubdomain.sfps") -Account YourSubdomain
15 | $sfClient = Get-SfClient -Name ((Join-Path $env:USERPROFILE "Documents") + "\YourSubdomain.sfps")
16 |
17 | #create script variable to store items and IDs that for cache lookup purposes
18 | #this is only needed for the full path details
19 | $script:StorageItemArray = @()
20 | $script:ItemIdArray = @{}
21 | $script:ItemIdArray.Add("", $null)
22 | $script:ItemIdArray.Add("root", $null)
23 |
24 | #Get shared folder root
25 | #note that this does not include size of versions that are stored but does list that there are versions
26 | function GetFileSize($ItemID, $ItemType)
27 | {
28 | #get the children of the passed in folder
29 | $Items = Send-SfRequest $sfClient -Method GET -Entity Items -Id $ItemID -Expand "Children,Owner"
30 | foreach ($item in $Items.Children)
31 | {
32 | #since folders return a 'file size' of all the children ignore unless it is a file
33 | if ($item.__type -eq "ShareFile.Api.Client.Models.File")
34 | {
35 | #CREATE A HASTHATBLE WITH ID/NAME
36 | #LOOKUP WITH PATH AND ADD FROM GET IF NOT THERE SO WE ONLY GET ONCE
37 | $FormattedPath = ""
38 |
39 | #pull apart the path and replace IDs with names
40 | foreach ($el in $Item.Path.Split("/"))
41 | {
42 | #check if we have this in cache
43 | if ($script:ItemIdArray.ContainsKey($el) -eq $true)
44 | {
45 | #make sure it isn't a value we want to ignore
46 | if ($script:ItemIdArray[$el] -ne $null) { $FormattedPath += ($script:ItemIdArray[$el] + "\") }
47 | }
48 | else
49 | {
50 | #get the name of the folder from the ID and add to cache
51 | $FolderName = Send-SfRequest $sfClient -Method GET -Entity Items -Id $el -Select "Name,Path"
52 |
53 | #if this is the root of the account we ignore it
54 | if ($FolderName.Path -eq "/root")
55 | {
56 | $script:ItemIdArray.Add($el, $null)
57 | }
58 | else
59 | {
60 | $script:ItemIdArray.Add($el, $FolderName.Name)
61 | $FormattedPath += ($FolderName.Name + "\")
62 | }
63 | }
64 | }
65 |
66 | #output an object to use in the report
67 | #could use the raw $item or could format to be 'pretty'
68 | $script:StorageItemArray += [PSCustomObject] @{Type=$ItemType; Path=$FormattedPath; Name=$item.Name; FileSizeBytes=$Item.FileSizeBytes; FileCount=$item.FileCount; DateModified=$item.CreationDate; DateAccessed=$item.ClientModifiedDate; DateCreated=$item.ClientCreatedDate; Creator=$item.CreatorNameShort; Owner=$items.Owner.Email; HasVersions=$item.HasMultipleVersions}
69 | }
70 |
71 | #determine type of item and recurse if a folder
72 | if ($item.__type -eq "ShareFile.Api.Client.Models.Folder") { GetFileSize $item.Id $ItemType}
73 | }
74 | }
75 |
76 | #Get the top-level shared folders and recurse each one
77 | $Items = Send-SfRequest $sfClient -Method GET -Entity Items -Id "allshared" -Expand "Children"
78 | foreach ($item in $Items.Children)
79 | {
80 | Write-Host ("Processing Shared Folder: {0}" -f $item.Name)
81 | GetFileSize $item.Id "Shared Folders"
82 | }
83 |
84 |
85 | $employees = Send-SfRequest $sfClient -Method GET -Entity Accounts/Employees -select "Id,Email"
86 | foreach ($employee in $employees)
87 | {
88 | Write-Host ("Processing Home Folder: {0}" -f $employee.Email)
89 | $HomeFolderID = "Users(" + $employee.Id + ")/HomeFolder"
90 | $EmployeeHomeFolder = Send-SfRequest $sfClient -Method GET -Entity $HomeFolderID -Select "Id,Name"
91 | $script:FullPath = ($EmployeeHomeFolder.Name + "\")
92 | GetFileSize $EmployeeHomeFolder.Id "Home Folder"
93 | }
94 |
95 | #output the report to CSV
96 | $script:StorageItemArray | Export-Csv -NoTypeInformation -Path ((Join-Path $env:USERPROFILE "Documents") + "\Storage." + (Get-Date -Format yyyy-MM-dd) + ".csv")
97 |
--------------------------------------------------------------------------------
/Test-ShareFileSnapIn/Utils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | namespace Test_ShareFileSnapIn
5 | {
6 | public class Utils
7 | {
8 |
9 | private static string _localFile = "ToUpload.txt";
10 | private static string _localFolder = "Folder1";
11 | private static string _sfFile = "DeepText.txt";
12 | private static string _sfFolder = "Folder1Q";
13 |
14 | ///