Skip to content

Instantly share code, notes, and snippets.

@HainanZhao
Created September 8, 2020 07:29
Show Gist options
  • Select an option

  • Save HainanZhao/953f92e2d706847b270f18351185ac0a to your computer and use it in GitHub Desktop.

Select an option

Save HainanZhao/953f92e2d706847b270f18351185ac0a to your computer and use it in GitHub Desktop.
Zip sub folders and upload them to Azure File storage
function ZipAndUpload
{
Param
(
[Parameter(Mandatory=$true, Position=0)]
[string] $rootFolder
)
cd $rootFolder
$folders = get-childitem -path $rootFolder | where-object {$_.Psiscontainer -eq "True"} |select-object Name
foreach ($folder in $folders)
{
$path= $folder.Name
$zip= $path + ".zip"
if(!(Test-Path $zip))
{
Compress-Archive -Path $path"\*" -DestinationPath $zip
}
AzCopy.exe copy $rootFolder "https://yourstorage.file.core.windows.net/foldername?sv=2020-03-28&ss=f&srt=sco&sp=rwdlc&se=2021-06-04T15:07:27Z&st=2019-06-04T07:07:27Z&spr=https&sig=xxxxxxxxxxxxxxxxxxxxxx" --include-path $zip
}
}
ZipAndUpload "C:\Your Folder Path\"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment