Demonstrate how to automate Azure File Sync deployments using PowerShell. This Lab automates the tasks performed manually in Azure Portal and over RDP on the Windows Server in this Lab.
An Azure RM template is included in infrastructure/
to create the environment:
Using Azure PowerShell, do the following to provision the resources:
.\New-Lab.ps1
Alternatively, you can perform a one-click deploy with the following button:
-
Start an Azure Cloud Shell PowerShell.
-
Create a file share:
$fileShareName = "sync" $resourceGroupName = Get-AzResourceGroup | select -ExpandProperty ResourceGroupName $storageAccount = Get-AzStorageAccount -ResourceGroupName $resourceGroupName | ` where StorageAccountName -like calabsync* New-AzureStorageShare -Context $storageAccount.Context -Name $fileShareName
-
Open the Cloud Shell editor:
code .
-
Paste in the
src/Install-AfsAgent.ps1
script for installing the Azure File Sync Agent on the VM. -
Save the script as Install-AfsAgent.ps1.
-
Use the VM Custom Script Extension to install the agent on the VM:
# Create a blog storage container that permits anonymous access to invidividual blobs $containerName = "deploy-afs" New-AzureStorageContainer -Name $containerName -Context $storageAccount.Context -Permission blob # Upload the Install-Afs.ps1 script to the blob container Set-AzureStorageBlobContent -File "Install-AfsAgent.ps1" ` -Container $containerName ` -Context $storageAccount.Context $fileUri = "$($storageAccount.Context.BlobEndPoint)$containerName/Install-AfsAgent.ps1" $Settings = @{ "fileUris" = @($fileUri) } $ProtectedSettings = @{ "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File Install-AfsAgent.ps1" } Set-AzVMExtension -ResourceGroupName $resourceGroupName ` -VMName $vm.Name ` -Location $vm.Location ` -Publisher "Microsoft.Compute" ` -ExtensionType "CustomScriptExtension" ` -TypeHandlerVersion "1.9" ` -Settings $Settings ` -ProtectedSettings $ProtectedSettings ` -Name provision
-
Create a sync group by running the
src/Deploy-Afs.ps1
script in the same fashion.
When finished, first delete the server endpoint, cloud endpoint, sync group, and registered server in Storage Sync Service (These resources cannot be deleted by deleting the resource group) and finally remove the remaining Azure resources with:
.\Remove-Lab.ps1