Search code examples
powershellcitrixsharefile

PowerShell Only get files within folders > move to root > delete folders only > upload to ShareFile


I have the below powershell script which has been developed to copy files from a local unc path to the application Citrix ShareFile. Whilst all is good on that aspect, one issue we are facing is that we strictly can not support folders due to Citrix ShareFile not accepting the copy as a new upload, however it is creating the file as a New Folder and not triggering the workflow correctly.

One thing I think that will make our life easier is simply not supporting folders which will work for our environment.

What i am thinking is a script that pulls all files and moves them to the root directory, deletes all folders, then uploads them to ShareFile.

The below script will copy the folder and all its contents.

I have had a look around and am struggling to get it to do as i wish.

## Add ShareFile PowerShell Snap-in
Add-PSSnapin ShareFile

## Create new authentication file
#New-SfClient -Name "C:\Sharefile\SVCACC.sfps" -Account aws

## Variables ##
$OutputAppReqFID = "fo4a3b58-bdd6-44c8-ba11-763e211c183f"
$Project = 'A001'
$LocalPath = "\\file.server.au\$project\DATA\DATA CUSTODIAN\OUTPUT\"
$sfClient = Get-SfClient -Name C:\sharefile\SVCACC.sfps
$OutputAppReqFID_URL = (Send-SfRequest $sfClient -Entity Items -id $OutputAppReqFID).Url

## Create PS Drive ##
New-PSDrive -Name "sfDrive-$($project)" -PSProvider ShareFile -Client $sfClient -Root "\" -RootUri $OutputAppReqFID_URL

## Copy all files from specified path to ShareFile, followed by moving files to another folder ##
foreach ($object in Get-ChildItem -Path $LocalPath) { 
    Copy-SfItem -Path $object.FullName -Destination "sfDrive-$($project):" 
    remove-item $object.FullName -Recurse
    }

## Remove PS Drive ##
Remove-PSDrive "sfdrive-$($project)"

Solution

  • Answered!

    I managed to apply a simple Where-Object that excludes the mode directory d----- from the upload

    Get-childitem -Path $LocalPath -Recurse | Where-Object {$_.Mode -ne "d-----"} | Select-Object -ExpandProperty FullName) 
    
    Seems to have worked a treat!