SameerBhat-0412 avatar image
0 Votes"
SameerBhat-0412 asked SathyamoorthyVijayakumar-MSFT edited

Unable to Run Az Commands in Azure Data Factory in Custom activity

I'm trying to run PowerShell script that has Connect-AzAccount command, from custom activity in azure data factory. But Connect-AzAccount is not recognized. I tried to import Az in PowerShell script that is in storage account, but getting below issue. Can someone let me know how to run Az commands that are in PowerShell from azure data factory custom activity

Import-Module : The specified module 'Az' was not loaded because no valid module file was found in
any module directory.
At D:\batch\tasks\workitems\adfv2-azurelib-batch-pool\job-1\a151dcda-8982-42d0-9e10-1005ceb9d140\wd
\RotateSasToken.ps1:1 char:1
+ Import-Module Az
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (Az:String) [Import-Module], FileNotFoundExcept
+ FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCom

Connect-AzAccount : The term 'Connect-AzAccount' 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 D:\batch\tasks\workitems\adfv2-azurelib-batch-pool\job-1\a151dcda-8982-42d0-9e10-1005ceb9d140\wd
\RotateSasToken.ps1:4 char:1
+ Connect-AzAccount

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SathyamoorthyVijayakumar-MSFT avatar image
1 Vote"
SathyamoorthyVijayakumar-MSFT answered SathyamoorthyVijayakumar-MSFT edited

Hello @SameerBhat-0412,

Welcome to the Microsoft Q&A platform.

The reason is because - the Batch Pool Nodes doesn't have the Az Modules installed by default. This is the reason why you are encountering the issue.

You'll have to install the Az module before executing any Az command lets.

You could have Start Task which goes ahead and installs the modules - Upon the start of the nodes.

Batch Account --> Pool --> Start Task


You can choose to install the modules that are necessary or complete Az module.

For illustration I have installed the Az.Accounts Module - which has the Connect-AzAccount

 powershell "Install-PackageProvider -Name NuGet -MinimumVersion -Force;
 Install-Module Az.Accounts -force "


Note :

  1. You would need the Admin priveleges to install the above packages. Hence, I used the User Identity as Pool AutoUser Admin.

  2. The installing of the Az Modules needed NuGet Package Provider as a dependency. Hence, I had installed the same before the installation of the Az Modules.

  3. You'll have to restart the existing nodes for the Start Task to be effective.

Hope this will help. Please let us know if any further queries.

  • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how

  • Want a reminder to come back and check responses? Here is how to subscribe to a notification

  • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

image.png (33.8 KiB)
image.png (64.3 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @SameerBhat-0412,

Just checking in to see if the above answer helped. If this answers your query, do click Accept Answer and Up-Vote for the same. And, if you have any further query do let us know.

1 Vote 1 ·

Hello @SameerBhat-0412,

Following up to see if the above suggestion was helpful. And, if you have any further query, please do let us know.

1 Vote 1 ·