PowerShell uses-debug to locate problems

Source: Internet
Author: User

PowerShell is like its name, very powerful, easy to use, so Microsoft basically all the mainstream enterprise-class products are supported Powershell,azure is no exception. While the azure portal is simple and intuitive, it is easier for many IT administrators or developers to use PowerShell scripting. I personally also like PowerShell very much.

If an error occurs when running PowerShell commands, in general, it is easier to find out what is wrong with the error message, but there is also a situation where the error message is not friendly, so how do you locate the specific fault? using the-debug parameter , it will open the PowerShell black box and display the specific running process in front of you, so it is convenient to locate the problem.

For example, I have recently encountered such a situation. Azure China (mooncake) A new relay service launched a preview version, called Hybrid connection, compared to the original WCF relay, because it is based on the web Socket, so more applicability, I was very happy to try, but in the creation of the Relay service namespace when the error.

PS c:\users\allenl> $relayns = new-azurermrelaynamespace-resourcegroupname $rgName-name $namespaceName-location $ Loca
tion
New-azurermrelaynamespace:operation returned an invalid status code ' NotFound '
At Line:1 Char:12
+ $relayns = New-azurermrelaynamespace-resourcegroupname $rgName-name ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ Categoryinfo:closeerror: (:) [New-azurermrelaynamespace], errorresponseexception
+ FullyQualifiedErrorId:Microsoft.Azure.Commands.Relay.Commands.Namespace.NewAzureRelayNamespace

Error message says NotFound, what's not found? The resource provider for this relay service is not registered yet? Resource group not created? Or the location is wrong, so I didn't find it?

With-debug, the answer will come out immediately. This command has been executed until the HTTP request has been successfully made to invoke the rest API that created the Relay service namespace, and the results are as follows

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
NotFound

Headers:
Pragma:no-cache
X-ms-failure-cause:gateway
x-ms-request-id:267981bf-f3c8-4037-8698-c7bdfd34b45e
x-ms-correlation-request-id:267981bf-f3c8-4037-8698-c7bdfd34b45e
x-ms-routing-request-id:chinaeast:20170705t025822z:267981bf-f3c8-4037-8698-c7bdfd34b45e
strict-transport-security:max-age=31536000; Includesubdomains
Cache-control:no-cache
date:wed, 02:58:21 GMT

Body:
{
"Error": {
"Code": "Resourcegroupnotfound",
"Message": "Resource Group ' relaydemorg ' couldnot being found."
}
}

Here we can see the specific cause of the error, because the resource group is not found, a check found that the original resource group name is provided wrong, so I did not find.

After the PowerShell found not clear enough error, with-debug debugging, you will find very useful.

PowerShell uses-debug to locate problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.