Hi There, just seeking some guidance on a issue,
1) ive created a script to out the state of running machines virtual machines in azure,
2) this then pipes out the contents to a .csv file
however i would like to the script to run and overwrite the existing file, however the switch i have researched don't seem to work,
for example Export-csv -Force
the script is below:
<#
.Synopsis
Retrieves stats from Azure of VM's and uploads a CSV file with data. Data is consumed in PowerBI
#>
function Get-VMStatus {
$VM | % {
$Status = (Get-AzureRMVM -Name $_.Name -ResourceGroupName $_.ResourceGroupName -Status).Statuses[1].DisplayStatus
$output = @{
Name = $_.Name
Status = $Status
ResourceGroup = $_.ResourceGroupName
}
$returnObj = New-Object -TypeName PSObject -Property $output
Write-Output $returnObj
}
}
#Setup Connection
$connectionName = "AzureRunAsConnection"
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
"Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
#Get VMs
$VM = Get-AzureRMVM | ? {$_.Name -like 'dcs*'}
#write file locally
$filename = "ServerCheckOutput"
($StatusObj = Get-VMStatus) | Export-csv -NoTypeInformation -Force -Path "$($filename).csv"
#Setup Storage account and upload
$StorageAccountName = "xxxxxxxxxxxxxxxxx"
$StorageAccountKey = "xxxxxxxxxxxxxxxw=="
$Ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey
Set-AzureStorageBlobContent -File "$($filename).csv" -Container "xxxxxx" -Context $ctx
and the Error i'm receiving in azure is below:
Any ideas or approach how to solve this?.
much appreciated
Logging in to Azure...
Environments Context
------------ -------
{[AzureCloud, AzureCloud], [AzureChinaCloud, AzureChinaCloud], [AzureUSGovernment, AzureUSGovernment]} Microsoft.Azur...
Set-AzureStorageBlobContent : One or more errors occurred.
At line:48 char:1
+ Set-AzureStorageBlobContent -File "$($filename).csv" -Container "dcsv ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzureStorageBlobContent], AggregateException
+ FullyQualifiedErrorId : AggregateException,Microsoft.WindowsAzure.Commands.Storage.Blob.SetAzureBlobContentCommand