1

I want to copy all the files in my server(azure vm) to a container (azure blob storage) is it possible through powershell? I'm new to powershell please help me out In any script with you please share

0

1 Answer 1

3

First, make sure you have installed the Az powershell module in your VM and the place you want to run the command. In my sample, I use my PC to run the command.

Try to store the script below in the PC, I use C:\Users\joyw\Desktop\script.ps1, the script will upload all the files in the folder C:\Users\xxxx\Desktop\test in your VM, you can change it to the path what you want.

script.ps1:

$context = New-AzStorageContext -StorageAccountName "<StorageAccountName>" -StorageAccountKey "<StorageAccountKey>"
$files = (Get-ChildItem "C:\Users\xxxx\Desktop\test" -recurse).FullName
foreach($file in $files){
    Set-AzStorageBlobContent -Context $context -File "$file" -Container "<container name>" -Blob "$file" 
}

Then run the command:

Connect-AzAccount
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -Name 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'C:\Users\joyw\Desktop\script.ps1'

If you want to login with non-interactive way, see this link.

Change the parameters to what you want, after uploading the file to the container, it will appear like the original file structure.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.