0

I want to install the Az.ManagedServiceIdentity in Self-Hosted Agent Pool in ADO. Does it require access and Az.Connect and Az.Account commands. I want to create an user assigned identity using below command - New-AzUserAssignedIdentity -ResourceGroupName PSRG -Name ID1 [I'm referring this link - https://learn.microsoft.com/en-us/powershell/module/az.managedserviceidentity/new-azuserassignedidentity?view=azps-5.8.0#examples] But getting Error that command is not recognized. Also this command does not work on Azure Agent pool as well and I'm getting the same error. What are the dependencies for to install the Az.ManagedServiceIdentity module.

wallezzi
  • 334
  • 1
  • 6
Yogesh Kulkarni
  • 339
  • 6
  • 24
  • Yes, it requires access and Az.Connect and Az.Account commands, only you sign in correctly, you can free to use these commands, it doesn't require Self-Hosted Agent Pool to do something. And you should use [Azure PowerShell task](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-powershell?view=azure-devops) in pipeline. – wallezzi Apr 27 '21 at 02:53
  • So in ADO how it will use Az.connect and Az.Account commands as I'm using a service principal to run the New-AzUserAssignedIdentity command. – Yogesh Kulkarni Apr 27 '21 at 06:25
  • Also, I have the module installed on one of the Agent Pool and still Im getting the error that New-AzUserAssignedIdentity is not recognized as the name of cmdlet, function.... – Yogesh Kulkarni Apr 27 '21 at 06:52
  • Do you [install the Azure Az PowerShell module](https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-5.8.0)? If yes, can you succeed to run these commands locally? – wallezzi Apr 27 '21 at 08:04
  • using Get-Installed Module I got the list of all the AZ modules installed on the agent pool which also shown Az.ManagedServiceIdentity modlue with 0.7.3 – Yogesh Kulkarni Apr 27 '21 at 08:12
  • If you install the modules under the agent's installed directory, the agent can identify it. If not, you need to add this installed path to the agent's capabilities, see: [Capabilities](https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser#capabilities) for details. – wallezzi Apr 27 '21 at 08:20
  • Its my Bad that only Agent Pool reboot was required. After the Agent pool reboot, the command New-AzUserAssignedIdentity worked for me. Not sure if this reboot is required for all the AZ modules that we install on ADO Agent pool or any other normal machines. – Yogesh Kulkarni Apr 28 '21 at 06:44
  • I think, if my answer helps, you might want to mark my answer instead to help community accurately. – Harshita Singh Apr 29 '21 at 17:28

2 Answers2

0

Pls use Azure PowerShell task for this.

This task is used to run a PowerShell script within an Azure environment. The Azure context is authenticated with the provided Azure Resource Manager service connection.

YAML snippet:

# Azure PowerShell
# Run a PowerShell script within an Azure environment
- task: AzurePowerShell@5
  inputs:
    #azureSubscription: Required. Name of Azure Resource Manager service connection
    #scriptType: 'FilePath' # Optional. Options: filePath, inlineScript
    #scriptPath: # Optional
    #inline: '# You can write your Azure PowerShell scripts inline here. # You can also pass predefined and custom variables to this script using arguments' # Optional
    #scriptArguments: # Optional
    #errorActionPreference: 'stop' # Optional. Options: stop, continue, silentlyContinue
    #failOnStandardError: false # Optional
    #azurePowerShellVersion: 'OtherVersion' # Required. Options: latestVersion, otherVersion
    #preferredAzurePowerShellVersion: # Required when azurePowerShellVersion == OtherVersion
    #pwsh: true # Optional. If true, then will use PowerShell Core pwsh.exe
Harshita Singh
  • 4,590
  • 1
  • 10
  • 13
0

Thanks for Yogesh Kulkarni's sharing that rebooting Agent Pool to make it find the new software. And it seems that rebooting is required to find new installed software and then register it to the service.

BTW, it is recommended to use Azure PowerShell task to run a PowerShell script within an Azure environment as singhh-msft replied.

wallezzi
  • 334
  • 1
  • 6