ShareFile-PowerShell icon indicating copy to clipboard operation
ShareFile-PowerShell copied to clipboard

Folder stopped syncing: Get-SfClient : Object reference not set to an instance of an object.

Open krhughes0 opened this issue 5 years ago • 1 comments

We have a script running automatically through task scheduler every couple of minutes to sync an in house folder to sharefile

Add-PSSnapIn ShareFile
Set-ExecutionPolicy RemoteSigned
$sfClient = Get-sfClient -Name “C:\Sharefile\Apipowershell.sfps”
New-PSDrive -Name sfdrive -PSProvider ShareFile -Root “/” -Client $sfClient
Sync-SfItem -LocalPath “c:\Scanback\*.*” -Upload -ShareFilePath “/Shared Folders/PAS Scanback” -Move
Remove-PSDrive sfdrive

It worked until 11/24 and now we receive the following error code when this script runs:

PS C:\Users\Administrator> C:\ShareFile\PAS_Upload.ps1 Get-SfClient : Object reference not set to an instance of an object. At C:\ShareFile\PAS_Upload.ps1:3 char:13

  • $sfClient = Get-SfClient -Name "C:\Sharefile\Apipowershell.sfps"
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Get-SfClient], NullReferenceException
    • FullyQualifiedErrorId : System.NullReferenceException,ShareFile.Api.Powershell.GetSfClient

New-PSDrive : Cannot bind argument to parameter 'Client' because it is null. At C:\ShareFile\PAS_Upload.ps1:4 char:68

  • ... rive -Name sfdrive -PSProvider ShareFile -Root "/" -Client $sfClient
  •                                                             ~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [New-PSDrive], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.NewPSDriveCommand

Sync-SfItem : Unable to cast object of type 'System.Management.Automation.PSDriveInfo' to type 'ShareFile.Api.Powershell.ShareFileDriveInfo'. At C:\ShareFile\PAS_Upload.ps1:5 char:1

  • Sync-SfItem -LocalPath "c:\Scanback*.*" -Upload -ShareFilePath "/Sha ...
  •   + CategoryInfo          : NotSpecified: (:) [Sync-SfItem], InvalidCastException
      + FullyQualifiedErrorId : System.InvalidCastException,ShareFile.Api.Powershell.SyncSfItem
    
    

Remove-PSDrive : Cannot find drive. A drive with the name 'sfdrive' does not exist. At C:\ShareFile\PAS_Upload.ps1:6 char:1

  • Remove-PSDrive sfdrive
  •   + CategoryInfo          : ObjectNotFound: (sfdrive:String) [Remove-PSDrive], DriveNotFoundException
    
    
    
    

Has anyone else received this issue or can help me decipher whats happenign here?

krhughes0 avatar Nov 30 '20 16:11 krhughes0

After over a week of troubleshooting, I was able to dial this down to the SFPS credential file. I'm not sure what caused this issue since the credential file is the same exact file that we have on dozens of other systems running this powershell script, the only difference is this is a server and it runs a task scheduler to automatically run the script every minute. My guess is either the server running the script somehow corrupted the credentials or sharefile is doing something to block that API account from uploading to their server.

In any case, I resolved the issue by running a new sfClient script and plugged in my own login (which uses 2FA, the API login is not supposed to have this). After it generated a new SFPS file, the script runs fine.

Solution:

Ran

New-sfClient -Name “C:\Sharefile\Apipowershell.sfps”

instead of

$sfClient = Get-sfClient -Name “C:\Sharefile\Apipowershell.sfps”

Then onces the new apipowershell.sfps file was created I went back to running the original script and it is uploading as before.

krhughes0 avatar Dec 03 '20 21:12 krhughes0