Note that there are some explanatory texts on larger screens.

plurals
  1. POPowerShell error uploading blob text to Azure: UploadText(string)
    text
    copied!<p>I have a powershell module which attempts to upload a blob to azure storage. Everything checks out until the last line which actually uploads the blob. </p> <p>I receive the following error:</p> <pre><code>Exception calling "UploadText" with "1" argument(s): "The specified resource does not exist." At line:1 char:1 + $blob.UploadText("asdasdfsdf") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : StorageClientException </code></pre> <p>I have also tried using the overload with 3 args, but the same issue exists there as well.</p> <p>Here is the module:</p> <pre><code>Function Add-BlobText { [CmdletBinding()] param( [Parameter(Mandatory = $true,Position = 0)] [string] $StorageAccount, [Parameter(Mandatory = $true,Position = 1)] [string] $Container, [Parameter(Mandatory = $true,Position = 2)] [string] $BlobName, [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [string] $BlobText ) #end param Add-Type -Path "C:\Assemblies\Microsoft.WindowsAzure.StorageClient.dll" Set-AzureSubscription -SubscriptionName "MySubName" $secondaryKey = (Get-AzureStorageKey -StorageAccountName $storageAccount).Secondary $creds = New-Object Microsoft.WindowsAzure.StorageCredentialsAccountAndKey($StorageAccount,$secondaryKey) $cloudStorageAccount = New-Object Microsoft.WindowsAzure.CloudStorageAccount($creds, $true) [Microsoft.WindowsAzure.StorageClient.CloudBlobClient]$cloudBlobClient = New-Object Microsoft.WindowsAzure.StorageClient.CloudBlobClient($cloudStorageAccount.BlobEndpoint) [Microsoft.WindowsAzure.StorageClient.CloudBlobContainer]$blobContainer = $cloudBlobClient.GetContainerReference($Container) [Microsoft.WindowsAzure.StorageClient.CloudBlob]$blob = $blobContainer.GetBlobReference($BlobName) $blob.UploadText($BlobText) } #end Function Add-BlobText </code></pre> <h2><em><strong>Update:</em></strong></h2> <p>I have been able to get this working as a binary module (below). If anyone can figure out why <code>UploadText()</code> works within a binary module but throws an exception in a script module, please let me know.</p> <pre class="lang-cs prettyprint-override"><code>[Cmdlet(VerbsCommon.Add, "BlobText")] public class AddBlobText : PSCmdlet { [Parameter(Mandatory = true, Position = 0)] public string StorageAccount { get; set; } [Parameter(Mandatory = true, Position = 1)] public string Container { get; set; } [Parameter(Mandatory = true, Position = 2)] public string BlobName { get; set; } [Parameter(Mandatory = true, ValueFromPipeline = true)] public string BlobText { get; set; } protected override void ProcessRecord() { PowerShell ps = PowerShell.Create(); ps.AddScript("Set-AzureSubscription -SubscriptionName 'MySubName'"); string keyScript = "( Get-AzureStorageKey -StorageAccountName " + StorageAccount + " ).Secondary"; ps.AddScript(keyScript); Collection&lt;PSObject&gt; result = ps.Invoke(); string secondaryKey = result[0].ToString(); StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(StorageAccount, secondaryKey); CloudStorageAccount storageAccount = new CloudStorageAccount(credentials, true); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(Container); var blob = container.GetBlobReference(BlobName); blob.UploadText(BlobText); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload