please check the following may help you
$resourceGroupName = "xxxx"
$storageAccName = "yyyy"
$fileShareName = "tttt"
$localDirectory = "C:\path\"
Connect-AzAccount
# Get the storage account context
$ctx = (Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).Context
$fileShare = Get-AZStorageShare -Context $ctx -Name $fileShareName
Function UploadFilesRecursively {
param (
[string]$sourceDir,
[string]$destDir
)
# Create the destination directory in the file share
New-AzStorageDirectory -Context $ctx -ShareName $fileShareName -Path $destDir -ErrorAction SilentlyContinue
# Upload files in the current directory
Get-ChildItem -Path $sourceDir -File | ForEach-Object {
$localFilePath = $_.FullName
$destFilePath = "$destDir/$($_.Name)"
Set-AzStorageFileContent -ShareName $fileShareName -Source $localFilePath -Path $destFilePath -Context $ctx
Write-Host "Uploaded: $localFilePath to $destFilePath"
}
# Recurse into subdirectories
Get-ChildItem -Path $sourceDir -Directory | ForEach-Object {
$subDirSource = $_.FullName
$subDirDest = "$destDir/$($_.Name)"
UploadFilesRecursively -sourceDir $subDirSource -destDir $subDirDest
}
}
$rootDirName = Split-Path -Path $localDirectory -Leaf
UploadFilesRecursively -sourceDir $localDirectory -destDir $rootDirName
# Disconnect from Azure Account
Disconnect-AzAccount