I need list query keys from Microsoft.Search/searchServices using PoweShell or API.
What I have investigate till now is:
Get-AzureRmResource -ResourceType "Microsoft.Search/searchServices/listQueryKeys" -ResourceGroupName 'resource-group-name' -ResourceName 'resource-name' -ApiVersion '2015-08-19'
Returns the array of objects with only names:
#{Name=a}
#{Name=query-key-created-from-powershell}
I have not found the API to get query keys.
There is easy way to get admin key:
Invoke-AzureRmResourceAction -Action listAdminKeys -ResourceType "Microsoft.Search/searchServices" -ResourceGroupName 'resource-group-name' -ResourceName 'resource-name' -ApiVersion 2015-08-19
But no way I can get QueryKeys. This is not working:
Invoke-AzureRmResourceAction -Action listQueryKeys -ResourceType "Microsoft.Search/searchServices" -ResourceGroupName 'resource-group-name' -ResourceName 'resource-name' -ApiVersion 2015-08-19
The docs refer only to create or delete Query Key.
How can I get Query Keys as name-key collection?
Try to use the following cmdlet:
Get-AzureRmSearchQueryKey -ResourceGroupName "resourceGroupName" -ServiceName "serviceName"
https://learn.microsoft.com/en-US/powershell/module/azurerm.search/get-azurermsearchquerykey?view=azurermps-6.11.0
Check that you have the correct version of Azure PowerShell.
To get the query key of the Azure Search service, #Victor Silva 's solution will work fine.
Get-AzureRmSearchQueryKey -ResourceGroupName "resourceGroupName" -ServiceName "serviceName"
I have download in my AzureDevOps task 'xxxx' 6.11.0 but AzureRM.Search is not part of it
To your further issue, because the AzureRM.Search module is in the preview version, it is not be included in AzureRM 6.11.0 module, refer to the Package Details in this link. So if you want to use this command Get-AzureRmSearchQueryKey, you need to install the AzureRM.Search independently, use Install-Module -Name AzureRM.Search -AllowPrerelease, refer to this link.
Update:
If you want to list query keys via API, you could use this REST API.
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Search/searchServices/{searchServiceName}/listQueryKeys?api-version=2015-08-19
Related
I'm tring to find a way how to get APIs stored on Azure in Microsoft.ApiManagement/service
I have tried different endpoints but none gave mi API with tags. Is there a way to do so?
Thank You!
Below are the PowerShell cmdlets for getting the list of APIs registered in an APIM Instance along with their individual API tags:
$ResourceGroupName = "resource_group_name"
$APImg = "APIM_Instance_Name"
$ApiMgmtContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $APImg
$Apis = Get-AzApiManagementApi -Context $ApiMgmtContext
foreach($Api in $Apis){
$ApiId = $Api.ApiId
$ApiName = $Api.Name
$tags = (Get-AzResource -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.ApiManagement/service/apis/tags -ResourceName "$APImg/$ApiId" -ApiVersion 2018-01-01).Name
Write-Host "Tags of" $ApiName : $tags
}
Result:
To get the list of APIs along with their tags using the REST API, below is the syntax:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/apisByTags?api-version=2021-08-01
Thanks to Microsoft Docs as they provided the sample response how it lists the APIs along with their tags for the above cmdlet:
Refer to the Azure API Management Rest APIs for more information.
Specifically, I am looking to write an automation runbook for changing a Function App's HTTP Version from it's 1.1 default to 2.0. I know there is a simple way to do this via CLI commands, but I'm trying to get a working solution using a powershell runbook.
So far, I've been able to find the setting by doing...
$FA = Get-AzFunctionApp -Name <foo> -ResourceGroupName <bar>
$FA.Config.Http20Enabled
False
I've attempted to alter $FA and then pipe it through Update-AzFunctionApp...
$FA.Config.Http20Enabled = $True
$FA | Update-AzFunctionApp
with no success.
Not sure if I'm close to the right solution but I can't seem to find any Azure functionality that changes platform settings in this way. Any insight would be much appreciated!
I was able to find a solution to my original question. Instead of using the AzFunctionApp cmdlets, I used AzResource.
$FA = Get-AzResource -ResourceGroupName <foo> -Name <bar> -ResourceType Microsoft.Web/sites/config -ApiVersion 2021-02-01
$FA.Properties.http20Enabled = $True
Set-AzResource -ResourceId $FA.ResourceId -Properties $FA.Properties
I presume other config settings can be changed along with the property I needed.
I found (as well as the Azure CLI) you can use the PowerShell cmdlets for Web Apps. These work on Azure Functions too!
For simple examples, perhaps to just toggle a feature you can call Set-AzWebApp in one line. Here are two examples:
(1) to enable HTTPS only:
Set-AzWebApp -Name $functionName -ResourceGroupName $rg -HttpsOnly $true
Or (2) to disable FTP/FTPs:
Set-AzWebApp -Name $functionName -ResourceGroupName $rg -FtpsState "Disabled"
For more complex property changes, like enabling HTTP 2.0. You can do this in just a few more lines of PowerShell. See for example:
$funcAsApp = Get-AzWebApp -Name $functionName -ResourceGroupName $rg
$funcAsApp.SiteConfig.Http20Enabled = $true
$funcAsApp | Set-AzWebApp
For more information see the MSDN help here: https://learn.microsoft.com/en-us/powershell/module/az.websites/set-azwebapp?view=azps-6.6.0
I have created an alert rule and associated it with a VM. Now trying to fetch the alert rule through Powershell, but getting null. What's wrong with this code ?
Get-AzAlertRule -ResourceGroupName 'pacbldnew'
see the alert rule
powershell code returning null
That is just a warning. The command should work, make sure the alert rule is existing.
Update1:
Try the command below to get what you want.
Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts
Update2:
If you want to get the details, try the script as below.
$names = (Get-AzResource -ResourceGroupName joywebapp -ResourceType microsoft.insights/metricAlerts).Name
foreach($name in $names){
Get-AzResource -ResourceGroupName joywebapp -Name $name -ResourceType microsoft.insights/metricAlerts | ConvertTo-Json
}
Joy is right in the way that the cmdlet should still execute as what you see is just a warning. However, this could be happening as Powershell support for newer metric alerts is still in the works as mentioned in the Official docs.
Also, as an alternative, if it helps, you could use Azure CLI to list newer Metric Alerts, as it now supports fetching elaborate results of queries belonging to the Microsoft.Insights/metricAlerts resource type.
For example:
az monitor metrics alert list -g <Resource group name> --output yaml
The result would look something like this:
You also get to choose out of the many output formats (json, jsonc, yaml, table, tsv) available with Az CLI.
Hope this helps!
Go to Azure- home security center and settings and filter and extract all rules
This query has worked for me:
Get-AzResource -ResourceType "microsoft.insights/scheduledqueryrules" -ResourceGroupName "Alert-RG"
I'm building my Azure Logic Apps worklow which is supposed to check some conditions and run following Powershell:
Stop-AzureWebsiteJob -Name MyWebsite -JobName MyWebJob
Start-AzureWebsiteJob -Name MyWebsite -JobName MyWebJob -JobType Continuous
The question is: what's the easiest way to invoke such script in Azure Logic Apps? It seems like there's no built in block/connector for Powershell so I'd like to know what are the possibilites. Or perhaps it might be easier to run az CLI command with similar operation
Finally I ended up with a solution which takes advantage of Azure Automation. From Azure Portal we can create new Resource typing in Automation:
Once the resource is created we can add new Runbook under runbooks tab:
Runbook can run Powershell Workflow and get authorized using AzureRunAsConnection option (details here). My sample Powershell which is supposed to restart WebJob an specific App Service looks like below:
Workflow RestartMyWebJob
{
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
$AzureContext = Select-AzureRmSubscription -SubscriptionId $Conn.SubscriptionID
$Apiversion = "2015-08-01"
$ResourceGroupName = 'My-Resource-Group-Name'
$ResourceName = 'My-Resource-Group-Name/My-AppService--WebJob-Name'
Invoke-AzureRmResourceAction -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName $ResourceName -Action stop -ApiVersion $Apiversion -Force
Invoke-AzureRmResourceAction -ResourceGroupName $ResourceGroupName -ResourceType Microsoft.Web/sites/ContinuousWebJobs -ResourceName $ResourceName -Action start -ApiVersion $Apiversion -Force
}
Having this Workflow setup we can run it from Azure Logic Apps by adding new block to our logic.
Currently, azure logic seems not support to run powershell and cli script, here is a voice in azure feedback, you could vote it.
Workaround:
If you want to start and stop the webjob, you can call the Kudu WebJobs API in the logic app.
You can follow the steps below.
1.Run the powershell command locally to generate the Authorization token of your web app.
$creds = Invoke-AzureRmResourceAction -ResourceGroupName joywebapp -ResourceType Microsoft.Web/sites/config -ResourceName joywebapp2/publishingcredentials -Action list -ApiVersion 2015-08-01 -Force
$username = $creds.Properties.PublishingUserName
$password = $creds.Properties.PublishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
The $base64AuthInfo is what we need, it should be like JGpveXdlYmFwcDI6NnJxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzRktSdXlUcU5acUUzdFhNb05j.
The token will never be changed except you reset the publish profile, so you just need to do this step once.
2.In the logic app, specific the Method, URI, Headers(The header should be like
Authorization: Basic JGpveXdlYmFwcDI6NnJxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxzRktSdXlUcU5acUUzdFhNb05j, note use space to separate the Basic and token), for example , I start a triggered webjob in my web app.
Triggered result:
So you just need to follow the steps above, for your issue, refer to the APIS:
Start a continuous job
Stop a continuous job
Create an Azure Function with an http trigger with Powershell as the function language (or any other supported language). Then you call the Function easily in the Logic app by calling an Http endpoint.
actually nowdays Azure provide this option, without creating runbooks and automation accounts. It is still in preview mode, but seems to be working !
You can also have your PowerShell code run in an Azure Container Instance supporting PowerShell and create an new Container Group from the Logic App workflow.
In AWS we have instance IDs to identify machines. What's the equivalent in Azure and how do I find that?
I'd like to list the instance ID in powershell so I can put that into a script.
If I have not misunderstood, I suppose you want to get the InstanceId of the VM in the Azure VM Scale set.
You could try to use Get-AzureRmVmssVM to get it.
Get-AzureRmVmssVM -ResourceGroupName <ResourceGroupName> -VMScaleSetName <VMScaleSetName>
Update:
If you want to get the ResourceId of azure resource, you could use Get-AzureRmResource to do it, just specify the properties what you want.
For example:
1.Get ResourceId of the specific resource:
$resource = Get-AzureRmResource -ResourceGroupName <ResourceGroupName> -ResourceType <ResourceType> -ResourceName <ResourceName>
$resource.ResourceId
2.Get ResourceIds of all resources in the specific resource group
$resource = Get-AzureRmResource -ResourceGroupName <ResourceGroupName>
$resource.ResourceId
3.Get ResourceIds of all resources under your subscription.
$resource = Get-AzureRmResource
$resource.ResourceId
The result will like(actual result will decided by your properties):