Skip to content

Instantly share code, notes, and snippets.

@debugthings
Created December 5, 2017 20:23
Show Gist options
  • Select an option

  • Save debugthings/6e2e2a6d6cfa5ef1efd147fb1650ea49 to your computer and use it in GitHub Desktop.

Select an option

Save debugthings/6e2e2a6d6cfa5ef1efd147fb1650ea49 to your computer and use it in GitHub Desktop.
Retrieve the URL inside of an Availability Test using a partial name or a partial URL
function Get-WebTestByURL {
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The Azure subscription id to search.')]
[Alias('SubId')]
[string]$subscriptionid,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='A substring of the URL to search for.')]
[Alias('PartialURL')]
[string]$urlfragment
)
process {
Write-Host ""
Write-Host "Looking up the URL that contains: '$urlfragment' against all webtest resources in the subscription with id: $subscriptionid"
Write-Host "Logging in to Azure..."
Login-AzureRmAccount | out-null
Write-Host "Selecting subscription $subscriptionid..."
Select-AzureRmSubscription -SubscriptionId $subscriptionid | out-null
Write-Host "Finding all webtests for subscription..."
$webtests = Find-AzureRmResource -ResourceType 'microsoft.insights/webtests'
Write-Host "Searching webtests for URL..."
Write-Host ""
foreach ($test in $webtests)
{
$testResource = Get-AzureRmResource -ResourceId $test.ResourceId
$testXml = [xml]$testResource.Properties.Configuration.WebTest
$firstUrl = $testXml.WebTest.Items.Request[0].Url
if ($firstUrl.Contains($urlfragment))
{
$resourceName = $testResource.ResourceName
Write-Host "$resourceName has the url $firstUrl"
}
}
}
}
function Get-WebTestURLByWebTestName {
[CmdletBinding()]
param
(
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='The Azure subscription id to search.')]
[Alias('SubId')]
[string]$subscriptionid,
[Parameter(Mandatory=$True,
ValueFromPipeline=$True,
ValueFromPipelineByPropertyName=$True,
HelpMessage='A substring of the webtest name to search for.')]
[Alias('PartialName')]
[string]$namefragment
)
process {
Write-Host ""
Write-Host "Looking up the URL in the webtests with a name that contans: '$namefragment' against all webtest resources in the subscription with id: $subscriptionid"
Write-Host "Logging in to Azure..."
Login-AzureRmAccount | out-null
Write-Host "Selecting subscription $subscriptionid..."
Select-AzureRmSubscription -SubscriptionId $subscriptionid | out-null
Write-Host "Finding all webtests for subscription..."
$webtests = Find-AzureRmResource -ResourceType 'microsoft.insights/webtests'
Write-Host "Searching webtests for URL..."
Write-Host ""
foreach ($test in $webtests)
{
if($test.ResourceName.Contains($namefragment)) {
$testResource = Get-AzureRmResource -ResourceId $test.ResourceId
$testXml = [xml]$testResource.Properties.Configuration.WebTest
$firstUrl = $testXml.WebTest.Items.Request[0].Url
$resourceName = $testResource.ResourceName
Write-Host "$resourceName has the url $firstUrl"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment