Transitioning from SFCLI

  • 1
  • Question
  • Updated 3 weeks ago
Our small architecture firm has been using SFCLI for years to transfer project files between us and our consultants on a daily basis.  Our Autodesk Revit building file for the project gets posted to a corresponding project file on ShareFile, and our consultants upload their files to their respective subfolders for that project on ShareFile, which then get transferred back to our server each night.

I have a script that runs these transfer commands for our file and each consultant file, for each project, which runs as a scheduled task on our server each night.  Works great.

Now I see that SFCLI is being phased out and we need to switch to the ShareFile PowerShell snap-in.  I have the snap-in set up, and I'm looking at the page describing what SFCLI commands look like in PowerShell: https://support.citrix.com/article/CTX207789?mkt_tok=eyJpIjoiWmpKa05UbGpOV1k0TmpJMyIsInQiOiJJOGNob3J...

My question is, the part near the top about authenticating and creating the temporary PSDrive, does that have to be part of a new script that I will write?  When I first typed in $sfc = New-SFClient in PowerShell, a ShareFile window popped up prompting me for my ShareFile username and password.  How do I automate that process to be part of a batch file?

Photo of patrick94gsr

patrick94gsr

  • 5 Posts
  • 1 Reply Like

Posted 3 weeks ago

  • 1
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 58 Posts
  • 7 Reply Likes
Hi Patrick,

Yes, the New-SFClient call is necessary to authenticate with ShareFile, and the PSDrive is needed to use the Sync-SfItem command.

The default behavior of New-SfClient is to query the user for credentials, but you can also do it programatically by adding additional parameters. (You can find out about additional available parameters by using the "help" command with any of our ShareFile commands.)
For example, you could do 

New-SFClient -Account <subdomain> -Credentials <credentials>

Where <subdomain> is your ShareFile account subdomain, and <credentials> is a PSCredentials object containing your ShareFile credentials.
(Edited)
Photo of patrick94gsr

patrick94gsr

  • 5 Posts
  • 1 Reply Like
Thanks, I figured out how to set up a login file for use with the SF PowerShell snap-in, and how to get it to run in the PowerShell environment.

However I'm a total n00b at PowerShell so I'm trying to figure out how to set up the power shell script so that it will run each night.  I created a PowerShell file with the commands for the credentials and PSDrive.  Then I wrote out a single line command to copy a project file from our server to the appropriate folder on ShareFile.  When typed manually into PowerShell it works fine.  I saved the commands as a .ps1 file, but when I try to run the file, it runs in the regular PowerShell and so it doesn't recognize the ShareFile commands like Get-SFClient and so on.

Do I need to save the script as a different file type?
Photo of Luke Skrzypek

Luke Skrzypek, Employee

  • 58 Posts
  • 7 Reply Likes
You should be able to add the ShareFile snap-in as the first part of your script.
Add-PSSnapin ShareFile
The ShareFile PowerShell Console is just PowerShell that runs these commands on startup:
$Host.UI.RawUI.BackgroundColor = 'DarkCyan'
$Host.UI.RawUI.ForegroundColor  = 'Yellow'
cd $env:USERPROFILE
cls
Add-PSSnapIn ShareFile
(Edited)
Photo of patrick94gsr

patrick94gsr

  • 5 Posts
  • 1 Reply Like
Thanks, I actually found that first command before you replied.

Now on to scheduling the script.  I think some other people have run into this.  I made a Scheduled Task to run PowerShell.exe with the -ExecutionPolicy Bypass argument, and the location of the .ps1 script.  But when the scheduled task starts, the PowerShell window comes up for a second or two, nothing shows in the console, and then it disappears.  Task Scheduler shows the Last Run Result as (0x1) with no other descriptive notes.
Photo of patrick94gsr

patrick94gsr

  • 5 Posts
  • 1 Reply Like
So I was using this how-to https://community.spiceworks.com/how_to/17736-run-powershell-scripts-from-task-scheduler where the author says he doesn't use the -file command.  But it wouldn't work for me until I added the -file command after -ExecutionPolicy Bypass.

So now it appears to be working!  Now I have to convert all my old SFCLI command lines to PowerShell commands.  Oh yay.

(Edited)