-
Notifications
You must be signed in to change notification settings - Fork 31
Home
This wiki provides examples for using the PowerShell SDK.
###Register To use the snap-in with your scripts, you will need to load it into a session. The best way to do this and get all the built-in formatting would be this:
Add-PSSnapIn ShareFile
###Authentication Authenticate to a session (and save for future use):
New-SfClient –Name "C:\Users\username\Documents\subdomain.sfps"
Note: The name provided here will be used to save the oAuth token for this connection. If you don't want to specify a full path, the file will be automatically created in "C:\Windows\System32\WindowsPowerShell\v1.0" (assuming you have access.) Subsequent scripts can access this user session without requiring an interactive user login or putting a password in your script. You should protect this token file as if it were credentials, though it can be revoked in the ShareFile application independent of a password if there is ever a concern of inappropriate access.
Load a saved session:
$sfClient = Get-SfClient –Name "C:\Users\username\Documents\subdomain.sfps"
###Calling the API Once you have a session, you can make calls to the API as follows:
Send-SFRequest –Client $sfClient –Method GET –Entity Users
Documentation for the ShareFile API entity model and more information is available here: https://developer.sharefile.com
###Using as a provider This snap-in also includes a provider that will allow you to access ShareFile content from within your scripts. This is useful for scripting out sync tasks that need to run unattended or to sync specific folders or in specific ways (like unidirectional sync or to access network shares.)
Create the provider:
New-PSDrive -Name sf -PSProvider ShareFile -Root / -Client $sfClient
Access the provider:
Set-Location sf:
Copy files to/from ShareFile:
Copy-SFItem sf:/Folder/Folder C:\LocalFolder
Copy-SFItem C:\LocalFolder\* sf:/Folder
Note: You can also use del (Remove-Item), cd (Set-Location), and dir (Get-ChildItem) once the provider is created.