2

I'm trying to make a script that creates automatic partions for SSAS via Powershell Runbook, but whenever I try to read in the xmla file i get the following error: enter image description here

enter image description here

My code that calls this is as followed:

$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName -Name $StorageAccountName

$blob = Get-AzureStorageBlob -Context $StorageAccount.Context -Container "Database name" -Blob "CreateNewPartition.xmla"

$file = $blob.ICloudBlob.DownloadText()
Invoke-ASCmd `
    -Database $AnalysisServiceDatabase `
    -InputFile $file `
    -server $AnalysisServiceServer 

When using the following code:

$memStream = New-Object System.IO.MemoryStream
$blob.ICloudBlob.DownloadToStream($memStream)
$readStream = New-Object System.IO.StreamReader($memStream, [System.Text.Encoding]::Unicode)
$memStream.Position = 0
$file = ($readStream.ReadToEnd() -replace "`0",'' | ConvertFrom-Json)

I get this error: enter image description here

And when trying this code:

$byteArray = New-Object Byte[] $blob.Length
$file = $blob.ICloudBlob.DownloadToByteArray($byteArray, 0)

I get this error: enter image description here

Souf
  • 369
  • 2
  • 16

1 Answers1

2

Easy fix.

In the first example, you are correctly reading the contents of the file from the blob. But, -InputFile is expecting a file path (e.g. C:\arst.xmla), and can't handle the raw contents of the .xmla file.

Instead, use the -Query parameter to pass the contents of the file to Invoke-ASCmd e.g.:

...

$query = $blob.ICloudBlob.DownloadText()
Invoke-ASCmd `
    -Database $AnalysisServiceDatabase `
    -Query $query `
    -server $AnalysisServiceServer 
HAL9256
  • 12,384
  • 1
  • 34
  • 46