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.
Related
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+
I wrote a power-shell and it is running fine from the windows machine by PS editor. System prompt for my user name to authenticate before running this.
$subscription = "dev"
Connect-AzAccount -Subscription $subscription
$keyvaultname = "kv-dev"
Update-AzKeyVaultNetworkRuleSet -DefaultAction Allow -VaultName $keyvaultname
when I am running the same script in Azure pipelines (using PowerShell task) it is throwing following error. I removed the Connect-AzAccount.
Update-AzKeyVaultNetworkRuleSet' 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.
How can I run this from azure pipelines using Power Shell task.
To execute the Azure PowerShell commands in pipeline job to manage Azure resources, you should use the Azure PowerShell task instead of PowerShell task.
You need to set up an Azure Resource Manager service connection (ARM connection) for use on the Azure PowerShell task. This ARM connection is used as the authentication, and you should not directly set the authentication in the PowerShell scripts.
Is there a way to trigger installer inside Azure VM with an API call or hook to get the installer running? Something like a PowerShell which I can be executed remotely, I just need to pass a parameter to it which it will pass the installer.
I need something simple and quick to get going,
I have looked into Custom Script Extension but I don't see how can I trigger it. Not sure what is the right thing to search for.
There are a couple options available for running commands in a VM.
While the Custom Script Extension is useful for configuration or management tasks, the Run command feature is very useful in that it is available even when the machine is not reachable. You can also run a Hybrid Runbook Worker with your custom scripts stored in an Automation account.
Refer to the following docs for more info:
Run scripts in your Windows VM
Run Command
You can use Invoke-AzVmRunCommand to do this. The script needs to be local to where the cmdlet is being run.
Invoke-AzVMRunCommand -ResourceGroupName 'rgname' -VMName 'vmname' -CommandId 'RunPowerShellScript' -ScriptPath 'sample.ps1' -Parameter #{param1 = "var1"; param2 = "var2"}
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