[Azure]使用Azure Powershell上传本地目录中的文件文件(递归)
来源:互联网 发布:淘宝账号违规怎么申诉 编辑:程序博客网 时间:2024/05/22 13:24
针对ASM环境的脚本:
param( # SrcDir [Parameter(Mandatory = $true)] [string]$SrcDir, # Subscription Name [Parameter(Mandatory = $true)] [string]$SubscriptionName, # StorageAccountName [Parameter(Mandatory = $true)] [string]$StorageAccountName, # Container Name [Parameter(Mandatory = $true)] [string]$ContainerName)function Upload ($folder, $SrcDirLen){ $subItems = Get-ChildItem $folder; foreach ($item in $subItems) { if ($item.Mode -eq "d-----") { Upload $item.FullName $SrcDirLen; } else { $fileName = "$folder\$item"; $destpath = $folder.Substring($SrcDirLen); $blobName = "$destpath/$item"; Write-Host "Copying $fileName to $blobName"; [void](Set-AzureStorageBlobContent -File $filename -Container $ContainerName -Blob $blobName -Context $storageAccount.Context -Force);} }}$cred = Get-Credential -Message "Use your Azure account to login";[void](Add-AzureAccount -Environment AzureChinaCloud -Credential $cred);[void](Select-AzureSubscription -SubscriptionName $SubscriptionName);$storageAccount = Get-AzureStorageAccount -StorageAccountName $StorageAccountName;upload $SrcDir $SrcDir.Length;Write-Host "All files in $SrcDir uploaded to $containerName
针对ARM环境的脚本:
param( # SrcDir [Parameter(Mandatory = $true)] [string]$SrcDir, # Subscription Name [Parameter(Mandatory = $true)] [string]$SubscriptionName, # ResourceGroupName [Parameter(Mandatory = $true)] [string]$ResourceGroupName, # StorageAccountName [Parameter(Mandatory = $true)] [string]$StorageAccountName, # Container Name [Parameter(Mandatory = $true)] [string]$ContainerName)function Upload ($folder, $SrcDirLen){ $subItems = Get-ChildItem $folder; foreach ($item in $subItems) { if ($item.Mode -eq "d-----") { Upload $item.FullName $SrcDirLen; } else { $fileName = "$folder\$item"; $destpath = $folder.Substring($SrcDirLen); $blobName = "$destpath/$item"; Write-Host "Copying $fileName to $blobName"; [void](Set-AzureStorageBlobContent -File $filename -Container $ContainerName -Blob $blobName -Context $storageAccount.Context -Force);} }}$cred = Get-Credential -Message "Use your Azure account to login";[void](Login-AzureRmAccount -EnvironmentName AzureChinaCloud -Credential $cred);[void](Select-AzureRmSubscription -SubscriptionName $SubscriptionName);$storageAccount = Get-AzureRmStorageAccount -Name $StorageAccountName -ResourceGroupName $ResourceGroupName;Upload $SrcDir $SrcDir.Length;Write-Host "All files in $SrcDir uploaded to $ContainerName.";
测试效果:
PS C:\Users\DanielHX> &C:\Users\DanielHX\Desktop\[ARM]upload_local_dir_to_storage.ps1 -SubscriptionName Internal-005 -StorageAccountName daneaststorag
e -ContainerName demo -SrcDir D:\test -ResourceGroupName daneastresourcegroup1
Copying D:\test\test1\1.txt to \test1/1.txt
Copying D:\test\test1\2.txt to \test1/2.txt
Copying D:\test\test2\test4\1.txt to \test2\test4/1.txt
Copying D:\test\test2\1.txt to \test2/1.txt
Copying D:\test\test2\2.txt to \test2/2.txt
Copying D:\test\test2\3.txt to \test2/3.txt
Copying D:\test\test3\1.txt to \test3/1.txt
Copying D:\test\test3\2.txt to \test3/2.txt
Copying D:\test\test3\3.txt to \test3/3.txt
Copying D:\test\test3\4.txt to \test3/4.txt
Copying D:\test\1.txt to /1.txt
All files in D:\test uploaded to demo.
PS C:\Users\DanielHX> &C:\Users\DanielHX\Desktop\[ASM]upload_local_dir_to_storage.ps1 -SrcDir D:\test -SubscriptionName Internal-005 -StorageAccountNa
me danieleaststorage -ContainerName test
Copying D:\test\test1\1.txt to \test1/1.txt
Copying D:\test\test1\2.txt to \test1/2.txt
Copying D:\test\test2\test4\1.txt to \test2\test4/1.txt
Copying D:\test\test2\1.txt to \test2/1.txt
Copying D:\test\test2\2.txt to \test2/2.txt
Copying D:\test\test2\3.txt to \test2/3.txt
Copying D:\test\test3\1.txt to \test3/1.txt
Copying D:\test\test3\2.txt to \test3/2.txt
Copying D:\test\test3\3.txt to \test3/3.txt
Copying D:\test\test3\4.txt to \test3/4.txt
Copying D:\test\1.txt to /1.txt
All files in D:\test uploaded to test.
- [Azure]使用Azure Powershell上传本地目录中的文件文件(递归)
- [Azure]使用Azure Powershell查看ARM模式下Azure存储中的vhd文件对应的虚拟机
- [Azure]使用Azure Powershell查看ASM模式下Azure存储中的vhd文件对应的虚拟机
- Azure VM上传小文件
- 1. 使用azure powershell 管理azure redis
- 使用Azure powershell 创建Azure虚拟机
- 使用VHDUpload上传VHD文件到云存储,并在Azure VM中加挂Azure Drive
- 使用 PowerShell 自动登录 Azure
- 使用 PowerShell 管理 Azure 磁盘
- [Azure]使用Powershell清理ARM中的无效资源
- Windows Azure 网站中的只读文件
- [Azure]使用Azure Powershell重新部署ASM虚拟机
- [Azure]ARM中使用Azure Powershell批量规划虚拟网络
- 使用 Azure PowerShell 管理 Azure 虚拟网络和 Windows 虚拟机
- azure使用vhd文件创建系统
- [Azure]使用Powershell克隆ARM虚拟机(非托管磁盘)
- [Azure]使用Powershell克隆ARM虚拟机(托管磁盘)
- 使用Powershell 管理Azure云端虚拟机!
- git 分支与合并,常用命令
- Android:你要的WebView与 JS 交互方式 都在这里了
- 在VS2015中使用easylogging++添加支持Unicode
- SEO和HTML的标签
- 使用Bootstrap编写时间范围选择控件
- [Azure]使用Azure Powershell上传本地目录中的文件文件(递归)
- 文档三段论写作技巧
- Ollydbg->设置
- 在eclipse里配置Python的开发环境以及Python第三方包的安装
- Ruby中的nil?,empty?与Rails中的blank?,present?
- XMU 1071 圣斗士黄金十二宫(七)银河星爆 【计算几何】
- 协方差矩阵
- 零配置-----3、ApplicationInitializer
- HDFS For core-site.xml