Enable Schedule Trigger in Azure Data factory through poweshell script - azure-devops

I am enabling schedule trigger in data factory through powershell script in release pipeline of Azure DevOps.
I have written script as below:
$triggersADF | ForEach-Object { Start-AzureRmDataFactoryV2Trigger -ResourceGroupName -DataFactoryName -Name $_.name -Force }
But I am getting below error.
The term 'Start-AzureRmDataFactoryV2Trigger' 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.
PowerShell exited with code '1'
How it can be done?

Install/update latest AzureRM.DataFactoryV2 module. And then
Restart your powershell.

Related

Azure cli running batch azure devops error

I get this error when using azure cli with multiple lines. Single commands are working fine.
The term 'call' is not recognized as the name of a cmdlet, function, script file, or operable program. Check...
I've just created a new release and replicated the behavior. You actually have Powershell selected in the Script Type field. Change it to Batch and it will work as expected.
EDIT
I thought I'd also share how to run Batch scripts from your repo and not worry if the dev has a call statement at the start of each line. I simply have a standardise script in my build which injects call before publishing the artifact
$Deploy_File = Get-Item "Azure-Commands.cmd"
$Deploy_File_Script = $Deploy_File | Get-Content
$Deploy_File_Script_Mod = #()
##Standardise commands for Azure CLI Deployment task
# Loop through Commands
foreach ($Command in $Deploy_File_Script) {
#Insert "CALL" before each azure command
if ($Command -like "az *") {
$Command = "call " + $Command
}
# Build Modified script array
$Deploy_File_Script_Mod += "$Command"
}
#Save to file
$Deploy_File | Set-Content -Value $Deploy_File_Script_Mod
#Output modified commands in file
$Deploy_File | Get-Content
Now you can just call the standardised deploy file from the task above

Automate Azure Data Factory triggers using release pipeline by using powershell task

I am new on DevOps, i am trying to change Azure Data Factory triggers starttime and endtime properties in azure data factory at deployment time using powershell.
I found this link and tried to follow in PowerShell. I am getting following error when i am running below command.
PS C:\> Set-AzDataFactoryV2Trigger -ResourceGroupName "ADF" -DataFactoryName "WikiADF" -Name "ScheduledTrigger" -DefinitionFile ".\scheduledTrigger.json"
Set-AzureRmDataFactoryV2 : The term 'Set-AzureRmDataFactoryV2' 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.
At line:1 char:16
+ $DataFactory = Set-AzureRmDataFactoryV2 -ResourceGroupName $ResGrp.Re ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Set-AzureRmDataFactoryV2:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I searched about this issue and found this issue as a bug in Microsoft official github account
If anyone able to resolved this issue or have already resolved, please help me.
Note: Azure DataFactory Triggers tag is not available in StackOverflow, so i am not able to add it.
Very agreed with Nick's opinion:
Any time youe see The term 'xyz' is not recognized as the name of a
cmdlet in powershell, it means you haven't installed the module.
Actually, in your issue, the error also caused by this reason. I think you should haven't installed the Az module for your Powershell.
The Az module is a rollup module for the Azure PowerShell cmdlets. Installing it can download all of the available Azure Resource Manager modules, include the Set-AzDataFactoryV2Trigger you are using, and makes their cmdlets available for use.
Try this command to install the Az module for your Powershell:
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Since as default, the PowerShell gallery isn't configured as a trusted repository for PowerShellGet, the first time you use the PSGallery you would see the prompt which need you ensure if you want to get the Az module from PSGallery. Just answer Yes or Yes to All is ok.
Then, you can execute the following command to check the Az module:
Get-InstalledModule -Name Az
When you see the following message, it means the Az module has exists in the Powershell:
Now, try this link again, it would be succeed.
You seemed to use PowerShell task instead of Azure PowerShell task (https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops) in your release pipeline.
You won't have any issue if using Azure PowerShell task.

Powershell Script Deployed through Intune - Command Not Found

Not sure if this is for stakoverflow or serverfault.
I am deploying a Powershell script using MS Intune. The script works when run locally, but when deployed I get the error below:
Remove-LocalGroupMember : The term 'Remove-LocalGroupMember' 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. At
C:\Program Files (x86)\Microsoft Intune Management
I am not sure why this commandlet is unavailable as it is definitely there if I open a powershell and run this command.
I am logging the $user variable to check that it is not null or running under a different context.
The code is quite simple as below:
$user = $(whoami)
$user | Out-File 'C:\powershelllog.log'
Remove-LocalGroupMember -Group Administrators -Member $user
I believe I've run into the same issue as you are having. I've been trying to create a local admin account on machines. Running the powershell script with the system context in Intune. What I've found is that you must check: "Run script in 64 bit PowerShell Host" inside of the Intune where you import powershell scripts.
Apparently not all commands are available with the 32 bit ps console running that way.
I also used the get-command to determine what module the command that was reporting not found was is in, and used the import-module at the top of my script in case.

Azure Function - PowerShell, installing az cmdlet :: The term 'az' is not recognized as the name of a cmdlet

I am attempting to install the az cmdlet onto Kudu for my Azure Function. I am currently following this guide:
How to install a PowerShell module in an Azure Function
... however - I am still getting the following error within my Azure Function:
az : The term 'az' 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.
at run.ps1: line 1
Steps I have done till now:
Created a module folder under D:\home\site\wwwroot\Communication_with_Azure_Container_Registry\>
Within the module folder I have added the contents of azure-cli/2.0.35/..., (which looks like this):
... Azure Function code is very simple to proof out the ability to install the cmdlet:
if (-not (Get-Module -Name "az"))
{
Write-Output "azure-cli not installed";
}
else
{
Write-Output "azure-cli installed";
}
$test = 'az --help'
Invoke-Expression $test
Write-output `n$test
Question:
Is there something within my configuration that is not allowing for the az cmdlet to install?
Is there an alternative way to gain access to the azure-cli without implementing the node module?
I solved the following part of your problem
az : The term 'az' 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. at run.ps1: line 1
If you execute
Test-Path -Path 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin'
You will probably get False. This means that you need to install the Azure CLI eg from https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest
I haven't testing this myself, but according to https://blogs.msdn.microsoft.com/powershell/2017/02/24/using-powershell-modules-in-azure-functions/ you should be able to do an Import-Module. In their example...
Write-Output “Loading Wunderlist Module”
import-module ‘D:\Home\site\wwwroot\HttpTriggerPowerShellDemo\Modules\Wunderlist\1.0.10\Wunderlist.psm1’
$Result = Get-Help Get-WunderlistUser | Out-String
Write-Output $Result
Install Azure CLI
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
This should give you the az command

How to use Azure Automation to start and stop the Service Fabric Nodes?

In our project, we want to use Azure Automation to start and stop Service Fabric Cluster nodes.
At first, we use the:
Enable-ServiceFabricNode -NodeName "Node1"
Disable-ServiceFabricNode -NodeName "Node1"
To start and stop the Nodes, it works in my Windows Powershell Script, but when we add it to the Azure Automation Script, it show
“The term ‘Enable-ServiceFabricNode’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name … ”
Then, we try to use the Azure Resources Manager to get the scale set VM, then start and stop the VM:
$Cred = Get-AutomationPSCredential -Name '***#***.com';
Add-AzureRmAccount -Credential $Cred
Set-AzureRmContext -TenantId ‘000000-786D-4361-A787-2C398163274F’
InlineScript
{
Stop-AzureRmVmss -ResourceGroupName "testRG" -VMScaleSetName "Test"
}
Also it works in my windows powershell script, but we try to add it to Azure Automation, it shows:
“The term ‘Stop-AzureRmVmss’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name … ”
The Azure Automation is use the Azure Powershell Script, right?
So is there any way that we can use the Azure Automation Script to Start and Stop the Service Fabric Cluster nodes?
Thanks so much!
Is this an on-premise cluster? Can you confirm if you enable Powershell script execution by running command below?
Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Force -Scope CurrentUser
By default, Windows blocks these scripts from running. To enable them,
you must modify your PowerShell execution policy. Open PowerShell as
an administrator and enter the following command:
You most likely don't have the latest Azure Modules. You can get the latest modules by following these steps -> https://learn.microsoft.com/en-us/azure/automation/automation-update-azure-modules