質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Azure

Azureは、マイクロソフトのクラウド プラットフォームで、旧称は Windows Azureです。PaaSとIaaSを組み合わせることで、 コンピューティング・ストレージ・データ・ネットワーキング・アプリケーションなど多くの機能を持ちます。

Q&A

解決済

2回答

1641閲覧

Azure ストレージアカウントにPowerShellを使用してVHDファイルをアップロードしようとすると403エラーが返される

agent

総合スコア16

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Azure

Azureは、マイクロソフトのクラウド プラットフォームで、旧称は Windows Azureです。PaaSとIaaSを組み合わせることで、 コンピューティング・ストレージ・データ・ネットワーキング・アプリケーションなど多くの機能を持ちます。

0グッド

0クリップ

投稿2021/01/13 12:23

PowerShellを使用して以下のコマンドでローカルにあるVHDファイルをAzure ストレージアカウントにアップロードしようとすると、次のようなエラーが出てしまいます。

エラーを発生させずにアップロードするにはどうすればよろしいでしょうか。

PowerShell

1PS D:\> Add-AzureRmVhd -ResourceGroupName "RG" -Destination "https://storageaccount.blob.core.windows.net/container/test.vhd" -LocalFilePath ".\test.vhd" -OverWrite 2MD5 hash is being calculated for the file D:\test.vhd. 3MD5 hash calculation is completed. 4Elapsed time for the operation: 00:00:00 5Creating new page blob of size 4194816... 6Add-AzureRmVhd : リモート サーバーがエラーを返しました: (403) 使用不可能 7発生場所 行:1 文字:1 8+ Add-AzureRmVhd -ResourceGroupName "RG" -Destination "https://stor ... 9+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 10 + CategoryInfo : CloseError: (:) [Add-AzureRmVhd]、StorageException 11 + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand

Azure Portalで[アクセス制御(IAM)]から[マイ アクセスの表示]にて現在ログインしているアカウントが「サービス管理者」として割り当てられていることは確認しました。
「所有者」として割当を追加しても解決しませんでした。
文末にエラー時のスタックトレースをすべて表示させたものを記載しました。

自動トラブルシューティング ツールを使用しても解決しませんでした。

Our automated troubleshooter did not detect any issues with your resource. You can help us by providing the right inputs below and ensuring that the format is as suggested in the watermark.

他に確認すべき事項がございましたらご指示ください。

Add-AzureRMVhdコマンドのリファレンス

ストレージアカウントの設定

JSON

1{ 2 "sku": { 3 "name": "Standard_LRS", 4 "tier": "Standard" 5 }, 6 "kind": "StorageV2", 7 "id": "省略", 8 "name": "省略", 9 "type": "Microsoft.Storage/storageAccounts", 10 "location": "japaneast", 11 "tags": {}, 12 "properties": { 13 "networkAcls": { 14 "bypass": "AzureServices", 15 "virtualNetworkRules": [], 16 "ipRules": [], 17 "defaultAction": "Allow" 18 }, 19 "supportsHttpsTrafficOnly": false, 20 "encryption": { 21 "services": { 22 "file": { 23 "enabled": true, 24 "lastEnabledTime": "2021-01-09T05:43:52.4994843Z" 25 }, 26 "blob": { 27 "enabled": true, 28 "lastEnabledTime": "2021-01-09T05:43:52.4994843Z" 29 } 30 }, 31 "keySource": "Microsoft.Storage" 32 }, 33 "accessTier": "Hot", 34 "provisioningState": "Succeeded", 35 "creationTime": "2021-01-09T05:43:52.4213920Z", 36 "primaryEndpoints": { 37 "blob": "https://"省略".blob.core.windows.net/", 38 "queue": "https://"省略".queue.core.windows.net/", 39 "table": "https://"省略".table.core.windows.net/", 40 "file": "https://"省略".file.core.windows.net/" 41 }, 42 "primaryLocation": "japaneast", 43 "statusOfPrimary": "available" 44 } 45}

スタックトレースをすべて表示させると以下のようになります。

PowerShell

1PS D:\> $Error[0] | Select-Object * 2 3 4writeErrorStream : True 5PSMessageDetails : 6Exception : Microsoft.WindowsAzure.Storage.StorageException: リモート サーバーがエラーを返しました: (403) 7 使用不可能 ---> System.Net.WebException: リモート サーバーがエラーを返しました: (403) 使用不可 89 場所 Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpResponseParsers.ProcessExpectedStatu 10 sCodeNoException[T](HttpStatusCode expectedStatusCode, HttpStatusCode actualStatusCode, T retVa 11 l, StorageCommandBase`1 cmd, Exception ex) 12 場所 Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<>c__DisplayClass2b.<SetMetadataImpl>b__2 13 a(RESTCommand`1 cmd, HttpWebResponse resp, Exception ex, OperationContext ctx) 14 場所 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndGetResponse[T](IAsyncResult ge 15 tResponseResult) 16 --- 内部例外スタック トレースの終わり --- 17 場所 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult r 18 esult) 19 場所 Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass4.<CreateCall 20 backVoid>b__3(IAsyncResult ar) 21 --- 直前に例外がスローされた場所からのスタック トレースの終わり --- 22 場所 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 23 場所 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Tas 24 k task) 25 場所 Microsoft.WindowsAzure.Commands.Sync.Upload.BlobMetaDataScope.Dispose(Boolean disposing 26 ) 27 場所 Microsoft.WindowsAzure.Commands.Sync.Upload.BlobMetaDataScope.Dispose() 28 場所 Microsoft.WindowsAzure.Commands.Sync.Upload.BlobCreator.CreateRemoteBlob() 29 場所 Microsoft.WindowsAzure.Commands.Sync.Upload.BlobCreator.CreateRemoteBlobAndPopulateCont 30 ext(UploadContext context) 31 場所 Microsoft.WindowsAzure.Commands.Sync.Upload.BlobCreatorBase.Create() 32 場所 Microsoft.Azure.Commands.Compute.Models.VhdUploaderModel.Upload(UploadParameters upload 33 Parameters) 34 場所 Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand.ExecuteCmdlet() 35 場所 Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord() 36 Request Information 37 RequestID:b7ec5a42-801e-009a-28a0-e9a9a0000000 38 RequestDate:Wed, 13 Jan 2021 11:40:41 GMT 39 StatusMessage:Server failed to authenticate the request. Make sure the value of Authorization h 40 eader is formed correctly including the signature. 41 ErrorCode:AuthenticationFailed 42 ErrorMessage:Server failed to authenticate the request. Make sure the value of Authorization he 43 ader is formed correctly including the signature. 44 RequestId:b7ec5a42-801e-009a-28a0-e9a9a0000000 45 Time:2021-01-13T11:40:41.5400248Z 46 47TargetObject : 48CategoryInfo : CloseError: (:) [Add-AzureRmVhd]、StorageException 49FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand 50ErrorDetails : 51InvocationInfo : System.Management.Automation.InvocationInfo 52ScriptStackTrace : <ScriptBlock>、<ファイルなし>: 行 1 53PipelineIterationInfo : {0, 1}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

アップロードするVHDファイルの保存先のパスに日本語が含まれているとエラーが発生しました。
VHDファイルを半角英数字のフォルダに移動させるとエラーは出ませんでした。

PowerShellのコマンドに日本語を含めていなくても、エラーは発生してしまいました。

質問当初はPS D:> などのようにコマンドを実行するカレントディレクトリの記載を一般化して記載していたため、一部実際に入力しているコマンドと異なった記載となっておりました。このせいで解決が遅れてしまったかもしれません。
申し訳有りませんでした。

投稿2021/02/15 07:31

agent

総合スコア16

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

Add-AzureRmVhd -ResourceGroupName "RG" -Destination "https://storageaccount.blob.core.windows.net/container/test.vhd" -LocalFilePath ".\test.vhd" -OverWrite

上記のコマンドで利用しているストレージアカウントの URL は "https://"省略".blob.core.windows.net/" と一致しておりますでしょうか?もし一致していない場合は、"https://"省略".blob.core.windows.net/container/test.vhd" に変更して再度実行ください。

もし一致している場合は、認証エラーということですので、SAS URI を利用したアップデートを試してみてはいかがでしょうか。

PS C:> Add-AzureRmVhd -Destination "http://contosoaccount.blob.core.windows.net/vhdstore/win7baseimage.vhd?st=2013-01 -09T22%3A15%3A49Z&se=2013-01-09T23%3A10%3A49Z&sr=b&sp=w&sig=13T9Ow%2FRJAMmhfO%2FaP3HhKKJ6AY093SmveO SIV4%2FR7w%3D" -LocalFilePath "C:\vhd\win7baseimage.vhd"

投稿2021/01/14 00:43

kongou-ae

総合スコア432

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

agent

2021/01/14 08:25 編集

ありがとうございます。 > 上記のコマンドで利用しているストレージアカウントの URL は "https://"省略".blob.core.windows.net/" と一致しておりますでしょうか? →はい。一致しております。 SAS URI を利用したコマンドを実行しましたが、エラーとなってしまいました。 ------ PS D:> Add-AzureRmVhd -Destination "https://"省略".blob.core.windows.net/container/test.vhd?sp=racwdl&st=2021-01-14T07:53:50Z&se=2021-01-15T07:53:50Z&sv=2019-12-12&sr=b&sig="省略" -LocalFilePath ".\test.vhd" -OverWrite MD5 hash is being calculated for the file D:\test.vhd. MD5 hash calculation is completed. Elapsed time for the operation: 00:00:00 Creating new page blob of size 4194816... Add-AzureRmVhd : リモート サーバーがエラーを返しました: (400) 要求が不適切です 発生場所 行:1 文字:1 + Add-AzureRmVhd -Destination "https://"省略".blob.core. ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (:) [Add-AzureRmVhd]、StorageException + FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.StorageServices.AddAzureVhdCommand ------ リファレンスには以下のようにSAS URIを使用しなくてもVHDをアップロードできるコマンド例が記載されています。SAS URIを使用せずにアップロードするための条件が何か存在するのでしょうか。 Add-AzureRmVhd -Destination "http://contosoaccount.blob.core.windows.net/vhdstore/win7baseimage.vhd" -LocalFilePath "C:\vhd\Win7Image.vhd"
kongou-ae

2021/01/15 11:26

PowerShell を実行している PC の時間がずれていないでしょうか?Add-AzureRmVhd が正常に動作する私の PC の時間をずらしたところ同じ403エラーが発生しました。
agent

2021/01/18 07:59

返信が遅くなりました。PCの時刻は正しかったです。NTPと同期されています。私の方ももう少し調べてみたいと思います。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問