1

I am currently writing a script in powershell that performs a test move of resources in Azure. I am currently receiving an error

Invoke-AzResourceAction : ResourceMoveNotSupported : Resource move is not supported for resource types 'microsoft.insights/activityLogAlerts'. CorrelationId: SomeLongStringOfRandomStuff At C:\Users\pcname\Documents\NewScript.ps1:16 char:9

  •     Invoke-AzResourceAction -Action validateMoveResources -Resour ...
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : CloseError: (:) [Invoke-AzResourceAction], ErrorResponseMessageException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.InvokAzureResourceActionCmdlet

I would like to be able to retrieve the correlation ID, and put that into an Excel sheet, how can I filter for this? I can't use a static substring as the names can be extremely difficult, however this error is on its own line, how can I go about this?

try
{
    Invoke-AzResourceAction -Action validateMoveResources -ResourceId $ResourceGroupID -Parameters @{ resources=@($ResourceID);targetResourceGroup = $resource.TargetResourceGroup }
    Write-Host $ResourceID + " Has been moved succesfully"
 
}
catch
{
    Write-Host $_.CorrelationID #This should be the object that is returned
}

1 Answers1

0

I would like to be able to retrieve the correlation ID

If your Invoke-AzResourceAction gives the correlationId object we can retrieve it.

In a PowerShell, Errors and Exceptions are structured objects. So we can format to our own way.

Refer Caching Error in PowerShell.

and put that into an Excel sheet

To pipe your error message into excel you can use the ConvertTo-Csv. First you have to add your error messages into array of objects and use ConvertTo-Csv.

Refer to Append PowerShell output to an Excel

Delliganesh Sevanesan
  • 4,146
  • 1
  • 5
  • 15