I am trying to nuke an azure subscription and I found this
https://www.frankysnotes.com/2016/12/need-to-nuke-azure-subscription.html
As I run the final part I got an error of
"Find-AzureRmResource : The term 'Find-AzureRmResource' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again."
Can someone help me how to fix this so I can nuke my Azure subscription?
Instead of using AzureRM module, use Az module as the former is now deprecated. To learn more about it, please see https://learn.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-7.5.0.
Simplest code to delete all resources from a subscription would be to list resource groups in that subscription and then delete them.
Your code would be something like:
Get-AzResourceGroup | Remove-AzResourceGroup
Please use Get-AzureRmResource instead of Find-AzureRmResource.
Find-AzureRmResource is depreacted.
Starting with version 6.0 of Azure PowerShell, Find-AzureRmResource have been removed and Get-AzureRmResource is supposed to be the workaround.
How to safely replace Find-AzureRmResource -ResourceType calls in Azure PowerShell 6.x+
Related
I have a notebook in an Azure Automation Account that I would like to call from SQL Managed Instance. Normally what I would do is to run:
Start-AzAutomationRunbook `
-AutomationAccountName "some-aa-name" `
-Name "notebook-name" `
-ResourceGroupName "rg-name" `
-Wait
My idea was to run it with a SQL Agent with a PowerShell task type. However, running it gives me an error:
The error information returned by PowerShell is: 'The term
'Start-AzAutomationRunbook' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and
try again.
Is there any way to make this cmdlet work on the managed instance?
Side note: I tested calling a WebHook and it works. However, it is not a very secure solution and it doesn't have the ability to wait for the completion.
Set-AzureRmDiagnosticSetting : A parameter cannot be found that matches parameter name 'Name'.
After executing below command in Azure powershell task
Set-AzureRmDiagnosticSetting -ResourceId $resourceId -Name $diagnosticsettingname -Enabled $true -Categories $logarray -MetricCategory $metricsarray -WorkspaceId $work
I am getting exception as
"Set-AzureRmDiagnosticSetting : A parameter cannot be found that matches parameter name 'Name'."
As per the specification there is the -Name parameter in it. So why I am getting this error
As mentioned in the comment, I think your version of AzureRM.Insights module is old, please update the module with:
Update-Module -Name AzureRM.Insights -Force
And you should note, the AzureRm module has been deprecated, it will not be updated anymore, so I recommend you to use the new Az module instead of AzureRm, see this link to migrate to Az, then use the command Set-AzDiagnosticSetting.
Adding to this, if you want to do both Azure Diagnostics and leveraging an Azure Pipeline to do it, while programmatically doing this at scale with Azure Policy, you can check out this solution which should make this a bit easier to consume.
https://aka.ms/azpolicyPipeline
Without pipeline but automating the policies / policy initiative you can take a look at this project here: https://aka.ms/AzPolicyScripts
I found this post looking for something else related to a bug in Az cmdlets so figured I'd post since I had this detail handy.
I need to get property like "DiskState", I am using cmd-let Get-AzureRMdisk, and what I got:
1) from my laptop, using connect-azurermaccount then get-azurermdisk, doesnt give expected property 2) I tried from Automatio account, created a runbook and then paste my code there, the same, I got more values but didn't get "diskstate" value 3) I see that I can get it from Azure Cloud Shell console. I would like to get this value from a script running as a runbook. Moreover I tried to use command like --> Get-AzureRmDisk | Where-Object ManagedBy -ne $null, but didnt get any interesting results. Is there any matheto do get this mentioned property "diskstate" using powershell runbook from Automation account?
Why not, the PowerShell command Get-AzureRMDisk show you the DiskState as you want:
Additional, I recommend you use the Az module of the PowerShell while the AzureRM module is Migrated to it. See Migrate Azure PowerShell from AzureRM to Az.
Update:
But in the Runbook Get-AzureRMDisk does not show the property, you need to use the Get-AzDisk to achieve the purpose after you import the Az module and it shows like this:
Im using Azure Automation and when I run Get-AzureRmVirtualNetwork i get an error as below. I realise it must need a module but how can you import the module in Azure Automation. Ive tried import-module and that errors too? Any ideas
Get-AzureRmVirtualNetwork : The term 'Get-AzureRmVirtualNetwork' is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
ok I worked it out you need to go to you azure automation account in the Azure Portal, then select the modules gallery and there you can import other modules
We use powershell script to start and stop the VMs using the build job. Please see the screenshot of the build job below
It is a simple powershell script to start an VM. The issue is when this job runs, we are getting an error and the build fails.
We get Parameter set cannot be resolved using the specified named parameters
But when we run it locally using the powershell console, the VMs get started.
Please find the error screenshot below
Am I missing something here.. Any help would be very much appreciated.
EDIT 1
Powershell script
$machines = #("machinename")
Select-AzureSubscription -Default "XXXYYYZZZ"
Foreach ($machine in $machines)
{
Try
{
Start-AzureVM -ServiceName $machine -Name $machine
}
Catch
{
}
}
I check your screenshot, I find you want to stop classic VMs. However, you logon Azure with cmdlet Add-AzureRmAccount and select subscription with cmdlet select-azurermsubscription, am I right? The two cmdlets are ARM mode cmdlets, you should use classic mode cmdlets.
Add-AzureAccount
According to your error, you could not use Select-AzureSubscription -Default "XXXYYYZZZ". Default could not add parameters. More information please refer to this link.
Try to use the following cmdlets.
Get-AzureSubscription
Select-AzureSubscription -SubscriptionName <YourSubscriptionName> -Default