How to login to share file using power shell script ?

Ayush Pandey 1 Reputation point
2020-11-03T14:19:46.18+00:00

Hi Team,

I am trying to login in share fileusing powershell. We are facing error "" New-PSDrive : Cannot bind parameter 'Client'. Cannot convert the "System.Net.NetworkCredential" value of type
"System.Net.NetworkCredential" to type "ShareFile.Api.Powershell.PSShareFileClient". "" .

My requirement is to use powershell and login in share file and download the files present in shared folder.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,504 questions
{count} votes

5 answers

Sort by: Most helpful
  1. Andreas Baumgarten 107.7K Reputation points MVP
    2020-11-03T16:51:25.867+00:00

    An example how to use New-PSDrive with credentials you can find here:

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive?view=powershell-7#example-4--create-a-persistent-mapped-network-drive-using-credentials

    $cred = Get-Credential -Credential Contoso\ServiceAccount  
    New-PSDrive -Name "S" -Root "\\Server01\Scripts" -Persist -PSProvider "FileSystem" -Credential $cred  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Ian Xue (Shanghai Wicresoft Co., Ltd.) 36,086 Reputation points Microsoft Vendor
    2020-11-04T08:03:51.43+00:00

    Hi,

    Please post your current powershell script and the full error message. It helps others understand your problem better.

    Best Regards
    Ian

    0 comments No comments

  3. Ayush Pandey 1 Reputation point
    2020-11-04T08:37:46.677+00:00

    Hi @Ian Xue (Shanghai Wicresoft Co., Ltd.) @Andreas Baumgarten ,

    Sorry for incomplete information .

    I am using below script to login in citrix share file to download a file via powershell. My expectation is it should login and give me the current directory of citrix share file path. But it is always giving me my local path.

    I am new to powershell and my requirement is to download a file from citrix share file daily. I went through some scripts but its no success. https://www.citrix.com/blogs/2014/05/16/getting-started-with-the-powershell-sdk/?_ga=2.110452933.1986677958.1604056761-676705981.1603441233

    Add-PSSnapin ShareFile
    $Username = 'ServicesSupport@$$$$$.net'
    $Password = '$$$$$$$'
    $Url = "https://miller.sharefile.com/Authentication/Login" --url for login
    $Path = "H:\Downloads\Ayush_work" --- Local path where I want to download the file
    $WebClient = New-Object System.Net.WebClient
    $WebClient.Credentials = New-Object System.Net.Networkcredential($Username, $Password)
    $ay = Get-Location
    Write-Host "filesizecounter:$ay"

    0 comments No comments

  4. Andreas Baumgarten 107.7K Reputation points MVP
    2020-11-04T10:57:40.86+00:00

    Maybe this PowerShell script will help even it's from 2015:

    https://github.com/citrix/ShareFile-PowerShell/blob/master/Samples/DownloadFiles.ps1


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  5. Ian Xue (Shanghai Wicresoft Co., Ltd.) 36,086 Reputation points Microsoft Vendor
    2020-11-05T08:48:43.403+00:00

    Hi,

    “YourSubdomain.sfps” is the file where you save your credential. You should run the line commented out to create that file the first time you run the script .

    $sfClient = New-SfClient -Name ((Join-Path $env:USERPROFILE "Documents") + "\YourSubdomain.sfps") -Account YourSubdomain  
    

    Best Regards,
    Ian

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.