Citrix ShareFile User Migration Script

Here is a nice PowerShell script I’ve created to migrate user from a specific Storage Zone to another Storage Zone. You can batch migrate users so it will only do the amount specified.

Run the script and it will ask for ShareFile credentials. Those will be saved in a file and not asked again (unless you delete the file). If you don’t set the Storage Zone controllers ID’s in the script it will list the available Storage Zones

Please leave a comment if you used the scrip or have questions/requests.

<#  Version 1.0

    Creator: Jeroen Tielen - Tielen Consultancy - www.jeroentielen.nl

    History:

    Version 1.0 - First version of the script. Only migrating users.

#>


# Make sure the Citrix ShareFile PowerShell SDK is installed: https://support.citrix.com/article/CTX207460
Add-PSSnapin Sharefile

# Declare variables
$SFAuthFile             = "$Env:TEMP\sharefile.sfps"             # Change this to required location and name. Or leave default
$SFZoneIDToMigrateTo    = "" # Leave this empty and the script will first show you all the currently available Zones
$SFZoneIDToMigrateFrom  = "" # Leave this empty and the script will first show you all the currently available Zones
$NumberOfUsersToMigrate = "1"                                    # This will only migrate the ammount of given users. So you can schedule the scipt and so batch migrate

# Authenticate against ShareFile and store the authentication file
If (Test-Path $SFAuthFile) {
    $SFClient = Get-SfClient –Name $SFAuthFile
} else {
    $SFClient = New-SfClient -Name $SFAuthFile
}

# Get Zone ID's
If ($SFZoneIDToMigrateTo.Length -eq 0 -or $SFZoneIDToMigrateFrom.Length -eq 0) {
    cls
    Write-Host -ForegroundColor White -BackgroundColor Red "No Zone ID to migrate to is configured. Here is the list with all currently available Zones:"
    Write-Host
    $Zones = Send-SFRequest –Client $SFClient –Method GET -Entity Zones
    ForEach ($Zone in $Zones) {
        $found = Send-SFRequest –Client $SFClient –Method GET -Entity Zones -Id $Zone.id
        Write-Host "Name :" $found.Name
        Write-Host "ÏD   :" $found.Id
        Write-Host
    }
    Write-Host -ForegroundColor White -BackgroundColor Red "Please copy and paste the correct ID's to the correct variables in the script."
}

# Migrating the users
$SFZoneIDToMigrateToJSON = '{"DefaultZone": { "Id":"' +  $SFZoneIDToMigrateTo + '" }}'
$SFUsersToMigrate = Send-SFRequest –Client $SFClient –Method GET -Entity Accounts/Employees -select "Id,Email"
$Counter = 1
ForEach ($UserTomigrate in $SFUsersToMigrate) {
    If ($Counter -le $NumberOfUsersToMigrate) {
        $User = Send-SFRequest –Client $SFClient –Method GET -Entity Users -Id $UserToMigrate.id -Expand "DefaultZone,DiskSpace,HomeFolder"
        If ($User.DefaultZone.Id -eq $SFZoneIDToMigrateFrom) {
            Write-Host -ForegroundColor White -BackgroundColor Red "Migrating:" $User.FullName "    " $User.Email
            Send-SfRequest -Client $SFClient -Method PATCH -Entity Users -Id $User.Id -Bodytext $SFZoneIDToMigrateToJSON
            $Counter++
        }
    } 
} 

2 thoughts on “Citrix ShareFile User Migration Script

  1. Thanks, this script was very useful. I used to migrate users from one store to another when we ran out of space. Do you a script for deleting disabled AD users from SF to reclaim licenses?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top