Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
krhughes0 opened this issue Nov 30, 2020 · 1 comment

Comments

@krhughes0
Copy link

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant