I'm having two runbooks of two different Powershell versions (5.1, 7.1). How to call a runbook (7.1) from runbook (5.1)?
Modules used:
AZ-SecurityInsights - 5.1 version (runbook 5.1)
AzSentinel - 7.1 version (runbook 7.1)
Need to pass resourcevariable as an input parameter to second runbook from first runbook.
My code:
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext
Start-AzAutomationRunbook -AutomationAccountName $automationAccountName -Name "ExportAlertRule" -ResourceGroupName $automationResourceGroupName
Error:
Object reference not set to an instance of an object.
What can I try next?
If the output stream of Start-AzAutomationAccount contains object, the command does not process the output stream correctly. For the same, you need to implement a polling logic, and use the Get-AzAutomationJobOutput cmdlet to retrieve the output.
For more information, refer below documents.
https://learn.microsoft.com/en-us/azure/automation/troubleshoot/runbooks#resolution-13
https://learn.microsoft.com/en-us/azure/automation/automation-child-runbooks#runbook-types
Related
I am new to Azure Power shell and Azure functions.
I have requirement where I have to execute Powershell command to stop PostgreSQL replication
I created the Azure function app with default options and created the function. Inside the function I updated with Get-AzSubscription. I am getting error for all azure commands.
"Get-AzResource/Get-AzSubscription/Get-AzModule" is not recognized as a name of cmdlet or function or Scrip file or executable program
but I am able to execute the "Get-Date" and get required results
Please suggest how to fixes to this issue
Thanks in advance
Ramabadran
"Get-AzResource/Get-AzSubscription/Get-AzModule" is not recognized as a name of cmdlet or function or Scrip file or executable program
To run the PowerShell cmdlets on Azure PowerShell Runtime Stack Function App/Project, you need to uncomment the Az module in requirements.psd1 with the Az module version i.e., compatible with PowerShell Version you're using the Function App:
requirements.psd1:
#{
'Az' = '8.*'
}
run.ps1:
using namespace System.Net
param($Request, $TriggerMetadata)
Write-Host "PowerShell HTTP trigger function processed a request."
Connect-AzAccount -Tenant '<Azure-tenant-id>' -SubscriptionId '<Azure-Subscription-Id>'
$SubscriptionInfo = Get-AzSubscription -TenantId "<Azure-tenant-id>"
Write-Host $SubscriptionInfo
$body = "Hello Jahnavi, This HTTP triggered function executed successfully."
Push-OutputBinding -Name Response -Value ([HttpResponseContext]#{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
Result:
Note: Also, Install the Azure modules in the Function app workspace of the VS Code Terminal using these cmdlets Install-Module Az, Import-Module Az.
I'm trying to implement a fairly simple PowerShell query, hosted in Azure Automation, to manage External Identities
I've set up a System Managed Identity and have successfully connected using Connect-AzAccount -Identity
But when I run it, it says You must call the Connect-AzureAD cmdlet before calling any other cmdlets
The next cmdlet is Get-AzureADPolicy, which I think triggered the above message
Following this blog, I tried this:
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext -ErrorAction Stop
Connect-AzureAD -TenantId $AzureContext.Tenant.TenantId -AccountId $AzureContext.Account.Id
and I get this: Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll'
Am not at all sure now what to do; any help appreciated
PS: I'm aware there are quite few related questions, but I have not been able to find an answer to this particular query ...
I was having the same issue and I resolved it by using the below commands. I have added comments to underline what each statement is meant for.
# Ensures you do not inherit an AzContext in your runbook. Out-Null is used to disable any output from this Cmdlet.
Disable-AzContextAutosave -Scope Process | Out-Null
# Connect to Azure with system-assigned managed identity.
$AzureContext = (Connect-AzAccount -Identity).context
# set and store context. Out-Null is used to disable any output from this Cmdlet.
Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext | Out-Null
With help from M/S support, I can now clarify the issue. The core point is that it is not possible to authenticate for AzureAD (with Connect-AzureAD) using Managed Identity; a Run As account must be used, at least currently
Further, for our use case, the Run As account had to have "Global Admin" role; "Owner" was not sufficient
It is of course possible to use Managed Identity for managing other Azure Resources (using Connect-AzAccount)
I am using Powershell to deploy a pipeline to an Azure Data Factory V2. I am passing a file with the JSON of the pipeline to be deployed.
But, the new pipeline created in the target ADF has a slightly modified JSON compared to the one passed as input. The source type tag under Lookup Activity has the value 'CopySink' instead of the value 'AzureSqlSink' specified in the input JSON file. Thus, Data Factory finds the deployed pipeline invalid.
The pipeline runs alright when I manually correct the tag values using the GUI though.
I have tried the below cmdlets. Both of them seem to have the same outcome.
Set-AzDataFactoryV2Pipeline -ResourceGroupName $DataFactoryResourceGroup -Name $svc.name -DataFactoryName $DataFactoryName -File "$currentPipelinePath" -Force
New-AzDataFactoryV2Pipeline -ResourceGroupName $DataFactoryResourceGroup -Name $svc.name -DataFactoryName $DataFactoryName -File "$currentPipelinePath" -Force
Appreciate any help on this issue. My intention is to automate deployment of ADF pipelines using Powershell.
This worked when I executed the command from the Admin Powershell console after upgrading all Az modules to their latest versions.
I'm trying to invoke a powershell script on to a Virtual Machine and retrieve the output of the script. I'm using the Invoke-AzureRmVMRunCommand cmdlet to invoke the script on the VM as shown below.
$ValidationResult = Invoke-AzureRmVMRunCommand -ResourceGroupName $VM.ResourceGroupName -VMName $VM.Name -CommandId "RunPowerShellScript" -ScriptPath $ValidationScript
When I execute the above cmdlet from a regular powershell terminal, I get the output as expected. However, whenever I'm putting this statement inside an automation runbook, I get null in almost all the fields as shown below
I don't see anything specific to this in documentation as well. Am I doing something wrong here?
Any help would be greatly appreciated! Thank you.
Update:
In the script, I'm logging the output using Write-Output cmdlet.
You need to either add the object name on last line of your script or use the Write-Output command. Otherwise it will not output anything.
The following lines both write an object to the output stream.
Write-Output –InputObject $ValidationResult
$ValidationResult
https://learn.microsoft.com/en-us/azure/automation/automation-runbook-output-and-messages
Hope this helps
This issue is most likely due to a reported bug in the AzureRM modules starting with version 5.7.0 / April 2018. Rolling back to version 5.6.0 / March 2018 is reported to fix it. Issue log: https://github.com/Azure/azure-powershell/issues/5982
My Apologies for the delayed response. I was using this in a runbook of type Powershell Workflow. Many of the PowerShell cmdlets behave differently when executed in workflows.
So in this case, what was happening is the Invoke-AzureRmVMRunCommand was executing correctly but the response was only the TYPE of the response and not the actual response object. Hence I was unable to see any values in the response's properties.
In order to make this work, I had to wrap the cmdlet call within an InlineScript {} block.
$ValidationResult = InlineScript {
$result = Invoke-AzureRmVMRunCommand -ResourceGroupName $USING:VM.ResourceGroupName -VMName $USING:VM.Name -CommandId "RunPowerShellScript" -ScriptPath $USING:ValidationScript
$result.SubStatuses[0].Message
}
The result is returned to $ValidationResult variable.
More detailed post is given here: https://amoghnatu.net/2018/04/15/get-output-of-script-executed-as-part-of-set-azurermvmcustomscriptexecution-cmdlet/
Thanks.
I am trying to use some of the Azure Powershell cmdlets in the AzureRM.ApiManagement module. A lot of the cmdlets require a context parameter, which is PsApiManagementContext object.
Following the guidance I have created a context using the New-AzureRmApiManagementContext cmdlet:
$ApiMgmtContext = New-AzureRmApiManagementContext
-ResourceGroupName "MyResourceGroup"
-ServiceName "MyApimService"
I then pass the context as a parameter to the cmdlet:
Get-AzureRmApiManagementUser -Context $ApiMgmtContext
The problem is that I get an error back as follows:
Get-AzureRmApiManagementUser : FormatException: One more parameters were not formatted correctly
I have used Fiddler to inspect the request that it generates and I can see that the body of the request is empty, so there must be something wrong with the way the context object has been created, even though I have basically copied the example in the microsoft docs. I have logged into my Azure subscription using Login-AzureRmAccount and selected the correct subscription prior to trying to create the context.
What am I doing wrong in the creation of the context object?