【发布时间】:2019-04-12 01:54:30
【问题描述】:
我想将服务器(azure vm)中的所有文件复制到容器(azure blob 存储)中,是否可以通过 powershell? 我是powershell新手,请帮帮我 在与您的任何脚本中,请分享
【问题讨论】:
标签: azure-devops azure-powershell powershell-remoting
我想将服务器(azure vm)中的所有文件复制到容器(azure blob 存储)中,是否可以通过 powershell? 我是powershell新手,请帮帮我 在与您的任何脚本中,请分享
【问题讨论】:
标签: azure-devops azure-powershell powershell-remoting
首先,确保你已经在你的虚拟机和你想运行命令的地方安装了Az powershell 模块。在我的示例中,我使用我的 PC 来运行命令。
尝试将下面的脚本存储在PC中,我使用C:\Users\joyw\Desktop\script.ps1,脚本会上传你VM中C:\Users\xxxx\Desktop\test文件夹中的所有文件,你可以把它改成你想要的路径。
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"
}
然后运行命令:
Connect-AzAccount
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -Name 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'C:\Users\joyw\Desktop\script.ps1'
如果您想以非交互方式登录,请参阅link。
把参数改成你想要的,文件上传到容器后,就和原来的文件结构一样了。
【讨论】: