0

I need to write to a variable value ExpectedHttpStatusCode.

I came to this conclusion, but I do not know what to do next?

$new = Get-AzResource -ResourceId /subscriptions/<subscriptions>/resourceGroups/us-test-vitalii/providers/microsoft.insights/webtests/us-test-vitalii-ui
$new.Properties.Configuration.WebTest 




<WebTest         Name="us-test-vitalii-ui"         Id=""         Enabled="True"
         CssProjectStructure=""         CssIteration=""         Timeout="120"         WorkItemIds=""         xmlns="http://mi
crosoft.com/schemas/VisualStudio/TeamTest/2010"         Description=""         CredentialUserName=""         CredentialPasswo
rd=""         PreAuthenticate="True"         Proxy="default"         StopOnError="False"         RecordedResultFile=""       
  ResultsLocale="">        <Items>        <Request         Method="GET"         Guid=""  
       Version="1.1"         Url=""         ThinkTime="0"         Timeo
ut="120"         ParseDependentRequests="True"         FollowRedirects="True"         RecordResult="True"         Cache="Fals
e"         ResponseTimeGoal="0"         Encoding="utf-8"         ExpectedHttpStatusCode="350"         ExpectedResponseUrl="" 
        ReportingName=""         IgnoreHttpStatusCode="False" />        </Items>        <ValidationRules>        <ValidationR
ule         Classname="Microsoft.VisualStudio.TestTools.WebTesting.Rules.ValidationRuleFindText, Microsoft.VisualStudio.Quali
tyTools.WebTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"         DisplayName="Find Text"
         Description="Verifies the existence of the specified text in the response."         Level="High"         ExectuionOr
der="BeforeDependents">        <RuleParameters>        <RuleParameter Name="FindText" Value="us-test-vitalii-ui" />
        <RuleParameter Name="IgnoreCase" Value="False" />        <RuleParameter Name="UseRegularExpression" Value="False" /> 
       <RuleParameter Name="PassIfTextFound" Value="True" />        </RuleParameters>        </ValidationRule>        </Valid
ationRules>        </WebTest>
2
  • Suppose you change that value, then what will you do with it? Are you asking just for a way to change the value or to change the value AND upload it back into Azure? Commented Aug 9, 2019 at 20:06
  • This xml seems broken. In theory, you should be able to use XPath to drill down to that attribute or cast the output to [xml] and traverse the object properties. With the XML in the shape that it is in, you will need to replace text. If we assume $variableValue has a status code, then you can use $new.Properties.Configuration.WebTest -replace '(?<=ExpectedHttpStatusCode=")\d+',$variableValue. Commented Aug 9, 2019 at 20:24

1 Answer 1

0

As mentioned in the comment, the XML seems broken. If you want to write to ExpectedHttpStatusCode, you could consider using the REST API Web Tests - Create Or Update, update the properties.Configuration. To call the API in PowerShell, you could use Invoke-RestMethod. For more details about call rest api with powershell, you could see this link, it's similar.

For the access token of the api, you could click the Try it button, login and copy the Authorization as below. Or if you want to generate manually, see this link.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.