Can anyone please tell me if there are any change for "Start-AzureVM" API?
It is getting struck with following command
Start-AzureVM -ServiceName (get-azurevm | where {$_.name -eq $VMName}).ServiceName -NAME $VMName
Also help me on where to look for latest azure API changes?
Make sure that you select a valid Azure Subscription using Select-AzureSubscription cmdlet before you use Start-AzureVM cmdlet.
When you do not have a valid Azure Subscription, there is a potential chance for all other Azure cmdlets behave awkwardly like you mentioned in your question.
Related
I'm new to Azure SQL database(no prior experience with databases) and currently trying to get a degree from microsoft learn. I'm stuck at this lesson and can't seem to figure it out, tho i assume it's something easy. Problem:
PS /home/stefanhtml> $server = Get-AzSqlServer -ResourceGroupName $resourceGroup
PS /home/stefanhtml> $logical_server = $server.ServerName
PS /home/stefanhtml> $databaseName = Get-AzSqlDatabase `
-ResourceGroupName $resourceGroup `
-ServerName $logical_server `
| Where DatabaseName -like Adventure*
Get-AzSqlDatabase:
Line |
3 | -ServerName $logical_server `
| ~~~~~~~~~~~~~~~
| Cannot validate argument on parameter 'ServerName'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
This is in Azure Cloud Shell from microsoft learn. Any reply would be much apreciated.
I got the same error in the Exercise Sandbox. But in portal Cloud shell, I run these commands successfully. It seems to be a common issues. I've submitted an feedback to MS here now. I think we will get news from Microsoft in time.
I also had the same error in the Exercise Sandbox and Azure Portal. For me it was due to restarting the project on unit 6 of 9. To run the code it required deploying the SQL database that was created in unit 3 in the same session as unit 6.
Effectively the code was trying to fine a SQL DB that didn't exist.
I have a azure powershell function app. The job of this function app is to generate azure storage account SAS token
I am using the following command to generate the token
$StartTime = Get-Date
$EndTime = $StartTime.AddMinutes(50.0)
$token = Get-AzStorageAccount -Name "<storage-account-name>" -ResourceGroupName "<resource-group-name>" | New-AzStorageContainerSASToken -Container <container-name> -Permission rdwl -StartTime $StartTime -ExpiryTime $EndTime
The code gave the valid sas token for some days. But since some time its throwing error
The Azure PowerShell context has not been properly initialized. Please import the module and try again
I saw a few questions mentioning "'session has not been properly initialized'" and nowhere mention for context.
I need help in resolving this issue
This is most likely caused by https://github.com/Azure/azure-functions-powershell-worker/issues/554. The recently released Az.Accounts 2.1.* introduced this regression. Until this is fixed in the modules, the temporary workaround is to roll back to Az.Accounts 1.9.5 by using these instructions: https://github.com/Azure/azure-functions-powershell-worker/issues/552#issue-732797653. Please note that this step is critically important:
Import-Module Az.Accounts -RequiredVersion '1.9.5'
Yes, "the context has not been properly initialized" is different with "the session has not been properly initialized". Maybe the module had been lost after run several days.
After checking the documents about using PowerShell modules, my suggestion is use Save-Module before publishing your Function. Consider deploying your function app to an App Service plan set to always on or to a Premium plan.
A more complex solution may also work is configure the context manually.
I have a pretty simple issue which perhaps is by-design but I just wanted to make sure I wasn't missing something...
Basically we use a lot of runbooks at my job, and this results in a ton of jobs generated under the automation accounts. I found I can search based on when the job was created and the name of the runbook, but is there no way to search based on the input parameters of the runbook?
This would help troubleshooting immensely as when someone says "well when were these users created" or "when was this instance upgraded" I can just search for that input param and answer the question quickly.
Perhaps it would be best to log all of the input parameters so then that is searchable via log analytics?
Thanks!!
Welcome to Stack Overflow!
Yes, Currently from Azure Portal there is no way to search based on the input parameters of the runbook. This can be raised as an feature request in this UserVoice / feedback forum. Responsible Azure feature / product team would triage and check the feasibility of the feature request and prioritize accordingly.
However, I believe as a workaround we can accomplish your requirement by leveraging Az PowerShell cmdlet Get-AzAutomationJob as explained in below screenshots.
So the command to use would be something like below:
Get-AzAutomationJob -AutomationAccountName "<YourAutomationAccountName>" -ResourceGroupName "<YourAutomationAccountResourceGroupName>" | foreach{Get-AzAutomationJob -ResourceGroupName $_.ResourceGroupName -AutomationAccountName $_.AutomationAccountName -Id $_.JobId | ?{$_.JobParameters.GetEnumerator().Where({$_.Value -contains "<KeyValueName>"})}}
or something like below if you want to validate 2 job parameters (one being key and another being a value)
Get-AzAutomationJob -AutomationAccountName "<YourAutomationAccountName>" -ResourceGroupName "<YourAutomationAccountResourceGroupName>" | foreach{Get-AzAutomationJob -ResourceGroupName $_.ResourceGroupName -AutomationAccountName $_.AutomationAccountName -Id $_.JobId | ?{$_.JobParameters.GetEnumerator().Where({$_.Value -contains "<KeyValueName>"}) -and $_.JobParameters.GetEnumerator().Where({$_.Key -contains "<KeyName>"})}}
Similarly you may have to tweak the command a bit to fit your needs.
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"
The new and soon to supercede AzureRsourceManager cmdlets all require a -ResourceGroupName parameter. Where am I expected to get this? Not including the UI, since that'd mostly defeat the purpose of automating.
Currently, I'm calling Get-AzureResourceGroup and trying each one until I get a hit. This is extremely slow - on the order of minutes. For example, to get WebApp information, I'm running this,
$groups = Get-AzureResourceGroup
foreach ($g in $groups)
{
if ($ResourceGroup) { $ResourceGroup.Value = $g.ResourceGroupName }
$app = Get-AzureWebApp -Name $Name -ResourceGroupName $g.ResourceGroupName -ErrorAction SilentlyContinue
Write-Verbose "Checking $($g.ResourceGroupName)"
if ($app)
{
$ResourceGroups[$g.ResourceGroupName] = #($ResourceGroups[$g.ResourceGroupName]) + $Name
return $app
}
}
If you go to the portal and navigate to your web app you can easily see which resource group it's in. See the screenshot below. What resource group is, is an arbitrary name to group resources. For example below you can see that it is grouping two Web Apps and two App Service Plans.
You can use the Get-AzureRmResourceGroup PowerShell command from Azure PowerShell without any parameter to get all the resource groups in very fast response time.
Reference Link: Get-AzureRMResourceGroup description
Note: You need to update your Azure PowerShell to the latest version for this new feature. The current version is 1.0.1 (November 2015 Update)
As #theadriangreen noted in his comment, it's faster to directly query the REST API. I found that some of the RM cmdlets actually do this anyway.
I've written a set of PowerShell functions to make using the API easier and faster (uses caching), in this gist.