azure - Powershell - 上传到 Azure blob 容器

标签 azure powershell blobstorage

我有一个 Azure 存储帐户,其中包含 Blob 容器和这些 Blob 容器中的文件夹(也称为容器?)。我有一个帐户名和帐户 key 来访问它,并且我可以使用 Microsoft Azure 存储资源管理器上传文件。我一直在寻找一个简单的脚本来将文件上传到特定的 blob 容器,但我已经找到了一个。卸载 RM 模块并安装 AZ 模块已经是一个挑战。这些示例似乎都非常复杂(安全性不是这个项目的问题),我只是无法让它们工作,而且我是这个主题的新手。

任何人都可以与我分享一行简单的 powershell 脚本来执行此操作吗?

最佳答案

我尝试使用以下 PowerShell 脚本将文件上传到特定的 Blob 容器并成功获得结果:

Connect-AzAccount

$ctx = New-AzStorageContext 
-StorageAccountName 'YourStorageAccountName' 
-StorageAccountKey 'YourStorageAccountKey' -Protocol Https

Set-AzStorageBlobContent 
-File "C:\Users\Downloads\YourFileName" `  //Your file path
-Container YourContainerName 
-Blob "YourFileName" `  
-Context $ctx

文件已成功上传到 blob 容器,如下所示:

enter image description here

要确认上述内容,请在门户中检查文件是否已上传,如下所示:

enter image description here

注意,要运行上述脚本,您需要 Azure 模块,例如 Az.Accounts Az.Storage 模块。你可以引用这个MsDoc安装相同的。

引用:

Quickstart: Upload, download, and list blobs - Azure PowerShell - Azure Storage | Microsoft Docs

关于azure - Powershell - 上传到 Azure blob 容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72767452/

相关文章:

google-app-engine - App Engine 上的云存储和安全下载策略。 GCS acl 或 blobstore

database - 如何使用 sqlplus 或 sql Developer 云连接连接到 Azure Oracle 12c 数据库

azure - 为 Azure 网站配置 web.config

powershell - Power Shell 测试连接,然后获取计算机名称或 mac-addr

powershell - 在 Powershell 控制台中使用 CTRL + D 退出和 CTRL + L 到 cls

python - Google AppEngine BlobInfo() 功能

c# - Azure AD - HTTP/1.1 401 未经授权 - Windows 服务

json - 如何在Azure Pipeline中将JSON文件设置为变量并在后续任务中使用它?

powershell - 在 PowerShell 1.0 中使用带有制表符的字符串拆分

azure - 并行上传 blob 时出现 "The specified block list is invalid"