PowerShell for Azure File Sync

While deploying Azure File Sync for a customer I’ve come across some useful PowerShell commands. Some are directly from Microsoft while others have been created by me to handle scenarios that may not be customer specific.

View file sync error report

When Azure File Sync is installed it includes tools to investigate the reason for tiles not syncing. If the portal states that there are files not being synced connect to the affected server endpoint and run the following PowerShell-cmdlets.

Set-Location $env:ProgramFiles\Azure\StorageSyncAgent

This will run the built in sync error report for all sync groups on the server. If you’d prepare to export the errors to a CSV-file just add a switch as below.

Set-Location $env:ProgramFiles\Azure\StorageSyncAgent
.\FileSyncErrorsReport.ps1 -CsvPath C:\temp\SyncErrors.csv

Resolving files with invalid characters

The major issue I encountered during the migration was files not syncing due to invalid characters in the file names returned in the report above as error code 0x8007007b. While the root cause is unknown this script will quickly remove the illegal characters from the file names.

$BasePath = "D:\Data" #Path where files with illegal characters are located

#Find all files in the path containing the illegal characted
$Items = Get-ChildItem $BasePath -Name *�*  -Recurse

#Rename the files replacing the illegal character
$Items | foreach {

$Path = $BasePath + $_

$Filename = $Path -split '\',-1,'SimpleMatch'
$Filename = $Filename[$Filename.Count-1]
$Filename = $Filename -replace "�",""

Rename-Item -Path $Path -NewName $Filename


If the files still appear in the sync error report a few minutes later I found that restarting the “Storage Sync Agent”-service helped.

Download all tiered files

This is primarily useful if you’re disabling tiering on a server or removing Azure File Sync for a specific share or all together.

Using the Azure Portal, disable tiering for the server endpoint. Connect to the server and run the following PowerShell command to download all files to the local server.

$Path = "D:\Data" #Local path of the files to download

Set-Location $env:ProgramFiles\Azure\StorageSyncAgent
Import-Module ".\StorageSync.Management.ServerCmdlets.dll"
Invoke-StorageSyncFileRecall -Path $Path

Force tiering of a specific file or folder

A tiered file is not actually available on the server endpoint. It’s content will automatically be made available if requested. If you have files that take up space on your server and want to free up that space you can use the following code. When applied to a directory the script will recursively tier all files in that folder and sub-folders.

$Path = "D:\Data" #Local path of the files you want to tier

Set-Location $env:ProgramFiles\Azure\StorageSyncAgent
Import-Module ".\StorageSync.Management.ServerCmdlets.dll"
Invoke-StorageSyncCloudTiering -Path $Path

Leave a Reply

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