从 ARM 上下文创建存储容器
Creating a Storage Container from an ARM context
我正在尝试设置一个包含存储帐户和容器的新资源组。除容器部分外,所有步骤均有效。从在线资源中,我了解到此 API 功能未移植到新的 ARM cmdlet——是否有可用的解决方法?
尝试 #1
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup4"
$location = "West Europe"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName "xzcczxda" -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
New-AzureStorageContainer -Name "images" -Permission Off
错误:
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
尝试 #2(基于 this)
与以前相同,但添加了 Import-Module AzureRM.Storage
并改为使用 New-AzureRmStorageContainer
。
错误:
New-AzureRmStorageContainer : The term 'New-AzureRmStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
尝试 #3(基于 this and )
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup9"
$location = "West Europe"
$storageAccountName = "teststorageaccount"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Write-Host "Fetching storage account information"
$storageKey = (Get-AzureStorageKey -StorageAccountName $storageAccountName).Primary
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey
New-AzureStorageContainer -Name "images" -Permission Off -Context $storageContext
错误:
Get-AzureStorageKey : ResourceNotFound: The storage account 'teststorageaccount' was not found.
New-AzureStorageContext : Cannot validate argument on parameter 'StorageAccountKey'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
尝试 #4(基于 this)
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup10"
$location = "West Europe"
$storageAccountName = "dasdaaadmb"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Write-Host "Fetching storage account information"
$storageKey = (Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroup).Value[0]
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey
New-AzureStorageContainer -Name "images" -Permission Off -Context $storageContext
错误:
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
尝试 #5(基于 )
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup11"
$location = "West Europe"
$storageAccountName = "addadadsadad"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroup
New-AzureStorageContainer -Name "images" -Permission Off
错误:
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
在这一点上我没有想法。如何从 ARM 上下文创建存储容器? This 似乎表明问题是因为我正在混合使用 ASM 和 ARM,我希望通过传递上下文可以解决这个问题(参见尝试 3 和 4)
归功于@GauravMantri 的解答!
当我逐字重新输入所有内容时,效果非常好。我已经改编了我的原始脚本并且 运行 没有问题。
然后我看了一下这两个字符串的组成。
void Main()
{
var correct = "New-AzureStorageContainer -Name \"images\" -Permission Off -Context $storageContext";
var wrong = "New-AzureStorageContainer -Name \"images\" -Permission Off -Context $storageContext";
for (var i = 0; i < Math.Max(correct.Length, wrong.Length); i++)
{
Console.Write("correct: " + (int) correct[i]);
Console.WriteLine("\twrong: " + (int) wrong[i]);
}
}
我已经突出显示了两个字符串的不同之处。
这让我想到 this question: "What's HTML character code 8203?" with the magical answer "It's the Unicode Character 'ZERO WIDTH SPACE' (U+200B)."
我正在尝试设置一个包含存储帐户和容器的新资源组。除容器部分外,所有步骤均有效。从在线资源中,我了解到此 API 功能未移植到新的 ARM cmdlet——是否有可用的解决方法?
尝试 #1
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup4"
$location = "West Europe"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName "xzcczxda" -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
New-AzureStorageContainer -Name "images" -Permission Off
错误:
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
尝试 #2(基于 this)
与以前相同,但添加了 Import-Module AzureRM.Storage
并改为使用 New-AzureRmStorageContainer
。
错误:
New-AzureRmStorageContainer : The term 'New-AzureRmStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
尝试 #3(基于 this and
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup9"
$location = "West Europe"
$storageAccountName = "teststorageaccount"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Write-Host "Fetching storage account information"
$storageKey = (Get-AzureStorageKey -StorageAccountName $storageAccountName).Primary
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey
New-AzureStorageContainer -Name "images" -Permission Off -Context $storageContext
错误:
Get-AzureStorageKey : ResourceNotFound: The storage account 'teststorageaccount' was not found. New-AzureStorageContext : Cannot validate argument on parameter 'StorageAccountKey'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
尝试 #4(基于 this)
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup10"
$location = "West Europe"
$storageAccountName = "dasdaaadmb"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Write-Host "Fetching storage account information"
$storageKey = (Get-AzureRmStorageAccountKey -Name $storageAccountName -ResourceGroupName $resourceGroup).Value[0]
$storageContext = New-AzureStorageContext -StorageAccountName $storageAccountName -StorageAccountKey $storageKey
New-AzureStorageContainer -Name "images" -Permission Off -Context $storageContext
错误:
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
尝试 #5(基于
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionName "Visual Studio Professional"
$resourceGroup = "MyResourceGroup11"
$location = "West Europe"
$storageAccountName = "addadadsadad"
New-AzureRmResourceGroup -Name $resourceGroup -Location $location
Write-Host "Created resource group"
New-AzureRmStorageAccount -ResourceGroupName $resourceGroup -AccountName $storageAccountName -Type Standard_RAGRS -Location $location -AccessTier Cool -Kind BlobStorage
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroup
New-AzureStorageContainer -Name "images" -Permission Off
错误:
New-AzureStorageContainer : The term 'New-AzureStorageContainer' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
在这一点上我没有想法。如何从 ARM 上下文创建存储容器? This 似乎表明问题是因为我正在混合使用 ASM 和 ARM,我希望通过传递上下文可以解决这个问题(参见尝试 3 和 4)
归功于@GauravMantri 的解答!
当我逐字重新输入所有内容时,效果非常好。我已经改编了我的原始脚本并且 运行 没有问题。
然后我看了一下这两个字符串的组成。
void Main()
{
var correct = "New-AzureStorageContainer -Name \"images\" -Permission Off -Context $storageContext";
var wrong = "New-AzureStorageContainer -Name \"images\" -Permission Off -Context $storageContext";
for (var i = 0; i < Math.Max(correct.Length, wrong.Length); i++)
{
Console.Write("correct: " + (int) correct[i]);
Console.WriteLine("\twrong: " + (int) wrong[i]);
}
}
我已经突出显示了两个字符串的不同之处。
这让我想到 this question: "What's HTML character code 8203?" with the magical answer "It's the Unicode Character 'ZERO WIDTH SPACE' (U+200B)."