Why am I getting an error when trying to remove a Microsoft.Insights/components resource? - powershell

I am trying to execute a PowerShell script that will sequentially remove Azure Resources from a resource group using a .ps1 file, and have isolated an error I am getting to whenever I try to remove the Microsoft.Insights/components resource using the command:
Remove-AzureRmResource -ResourceId "/subscriptions/e41d3122-bbd8-48dc-a212-0337139671cc/resourceGroups/TestRG/providers/Microsoft.Insights/components/WA-Stag-API-EMEA-zgqmgcwnigknu"
The error I'm getting after running this once is as follows:
Remove-AzureRmResource : {"code":"Message: {\"Errors\":[\"One of the
specified pre-condition is not met\"]}","message":"Message:
{\"Errors\":[\"One of the specified pre-condition is not
met\"]}\r\nActivityId: 845b19fa-b6b4-4952-9b62-75bfc6e98646, Request
URI:
/apps/1921ec42-1c88-4fdd-8d6c-78646cba4b15/services/a32b484a-6ee1-4ad7-ab43-4e9
d57bb0b81/partitions/fab8c193-3ec3-45e8-b7a6-0e21d1e071da/replicas/131441657816991616p","innererror":{"diagnosticcontext":"597ea546-7625-474d-b27f-560a1140a652","time":"2017-
07-18T19:41:25.3734216Z"}} At line:1 char:1
+ Remove-AzureRmResource -ResourceId "/subscriptions/e41d3122-bbd8-48dc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Remove-AzureRmResource], ErrorResponseMessageException
+ FullyQualifiedErrorId : Conflict,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.RemoveAzureResourceCmdlet
From what I can tell, there seems to be some kind of "pre-condition" that needs to be met before you can delete it... but the weirdest part is that if I execute the same command again, I don't get an error and the resource is successfully deleted...
Is there any reason why this would fail once, but then succeed in being deleted after executing again?

This is because the Insights is used by your Web APP. Please refer to this link. When you enable client side monitoring, you will get the error log. I test in my lab, I get the same result with you.
If you want to avoid this error log. Please refer to the following steps:
1.Delete APPINSIGHTS_JAVASCRIPT_ENABLED key.
2.Restart your app.
3.Delete Insights.

Related

How to debug Push-AppveyorArtifact when it fails

As part of my CI running on AppVeyor I'm uploading a log from the installer using Push-AppveyorArtifact. While most of the time it works perfectly for a single PR the upload fails with the following output:
Push-AppveyorArtifactInternal : Error uploading artifact to the storage: One or more errors occurred.
At C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api\build-worker- api.psm1:209 char:2
+ Push-AppveyorArtifactInternal -FullPath $fullPath -FileName $File ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Push-AppveyorArtifactInternal], Exception
+ FullyQualifiedErrorId : System.Exception,Appveyor.BuildAgent.Api.Utils.PushAppveyorArtifactInternalCmdlet
Command executed with exception: Error uploading artifact to the storage: One or more errors occurred.
Given this output is not very informative I am at a loss and have no idea how this can be debugged further. List of things I've tried:
Contacted AppVeyort support - no reply for over a month
Made sure that the file I am trying to upload exists and is not empty
Since as part of the problematic pull request the process which creates this file fails to exit properly I've tried killing it manually, confirmed that it is no longer active and retied the upload - same error.
Tried increasing the verbosity of Push-AppveyorArtifact by providing -Verbose -Debug which appears to be the highest verbosity level possible but no more info shows up.
It looks like the following sequence causes the upload to fail:
The process which creates a log file which fails to upload later on is started and then we're waiting for it to finish with wait-process for 3 minutes
If it finishes in the specified time the log file created it creates is uploaded successfully
Since we want to know if the process exited or not we need to specify -ErrorAction Stop for the wait-process invocation.
If wait-process raises an exception i.e. process is still running the Push-AppveyorArtifact fails with the error shown above

Powershell script for Power BI administration doesn't work in standard PS terminal

When I run Connect-PowerBIServiceAccount in Powershell it pops up the Okta window for me to authenticate and that seems to work. But when I run Get-PowerBIWorkspace -All I get this:
Get-PowerBIWorkspace : An error occurred while sending the request.
At line:1 char:1
+ Get-PowerBIWorkspace -All
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (Microsoft.Power...owerBIWorkspace:GetPowerBIWorkspace) [Get-PowerBIWorkspace], HttpRequestException
+ FullyQualifiedErrorId : An error occurred while sending the request.,Microsoft.PowerBI.Commands.Workspaces.GetPowerBIWorkspace
I've done hours of googling and found nothing helpful. I'm using version 1.0.896 of the Powershell modules from MicrosoftPowerBIMgmt. I've tried using Fiddler but that didn't help me. Is there a way to debug? I've tried using "-Debug" and "-Verbose" but neither helped.
UPDATE: The full script I'm trying to use to list out all my workspaces/reports/datasets gets further when executed from the terminal within Visual Studio Code but I don't know why. Eventually it fails too, saying "Operation returned an invalid status code 'TooManyRequests'."

VSTS release only logs the 1st line of a Powershell exception as an error. How can I log the full exception details without enabling debug?

If I run this code (containing a null reference) in Powershell ISE
$result = $nonExistentString.Substring(0,4)
An exception is thrown and the following is output to the console
You cannot call a method on a null-valued expression.
At line:1 char:1
+ $result = $nonExistentString.Substring(0,4)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
However, if I run the same code in a VSTS release as a powershell inline script, the release log will only output the following :
2017-11-30T13:23:26.9471504Z ##[error]You cannot call a method on a null-valued expression.
This isn't enough detail to facilitate problem resolution in more complex scripts. I know I can run the scripts in debug mode and the full exception record is logged as debug entries, but this would mean we would need to run all scripts in debug at all times in order to get full exception details when they occur. Does anyone know if it possible to configure VSTS to log full exception details without having to enable debug?

ADAL in Azure Automation: Type not loading intermittantly

I'm working on an Azure Automation script where I need to retrieve an access token to call the AAD Graph API. I wanted to use ADAL to do this so I zipped up Microsoft.IdentityModel.Clients.ActiveDirectory.dll and uploaded it as a module. When I run from the test blade, it sometimes works, and sometimes fails with this error:
New-Object : Cannot find type [Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential]: verify that the
assembly containing this type is loaded.
At line:22 char:9
+ $cred = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredent ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
When it fails I just run it again and it works. Now I've published and scheduled this runbook as a daily job 3 days ago. So far it has failed every day with this same error.
Has any one else seen this? Any suggestions on next steps?
I fixed this by adding the following line to my script:
Add-Type -Path "C:\Modules\User\Microsoft.IdentityModel.Clients.ActiveDirectory\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
Still not sure why it was working intermittently before. I guess depending on what else was going on ADAL may or may not have been loaded?

Windows Azure Powershell command Get-AzureWebsite results in error String was not recognized as a valid Boolean

I'm trying to manage some of my Azure Services via Powershell, using http://windowsazurewebsitescheatsheet.info/#powershell as a starting point. I was able to download and import my subscription settings just fine (Import-AzurePublishSettingsFile and Select-AzureSubscription)
After choosing my subscription, I'm attempting to run the Get-AzureWebsite command to view all of my websites, and continue onward from there. When I run that command, however, I get the following:
Import-AzurePublishSettingsFile "C:\AzureCredentials.publishsettings"
Select-AzureSubscription "My Azure Subscription"
Get-AzureWebsite
Get-AzureWebsite : String was not recognized as a valid Boolean.
At line:1 char:1
+ Get-AzureWebsite
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Get-AzureWebsite], FormatException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Websites.GetAzureWebsiteCommand
Anyone have similar issues? I get this error if I run the command as stated above, or if I specify the name of my website. TIA for any help!
This might be related to a known issue enumerating a sites with SSL bindings
There was new release of Windows Azure Powershell released on 02/12. Please try with the new version.
Please run the command again with -Debug turned on, this will display request and response messages and make it easier to pinpoint the issue.