Connect-AzContainerRegistry command not working

A M ANISUL HUQ 0 Reputation points
2025-03-28T07:11:08.6033333+00:00

Hi folks,

I can connect to my Azure account and my subscription using

Connect-AzAccount -Subscription

and

Set-AzContext -Subscription

commands. I have created storage accounts, VMs etc. without a hitch using Powershell. However, when I am trying to use "Connect-AzContainerRegistry", I am getting the error:

Connect-AzContainerRegistry : The 'Connect-AzContainerRegistry' command was found in the 
module 'Az.ContainerRegistry', but the module could not be loaded. For more information, run 
'Import-Module Az.ContainerRegistry'.
At line:6 char:1
+ Connect-AzContainerRegistry -Name containerregistrydemo160980
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Connect-AzContainerRegistry:String) [], Comma 
   ndNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

And when I try to import the module, I get:

Import-Module : Could not load file or assembly 'file:///C:\Users\15146\OneDrive\Documents\Wi
ndowsPowerShell\Modules\Az.ContainerRegistry\2.2.3\Microsoft.Azure.Management.ContainerRegist
ry.dll' or one of its dependencies. The cloud file provider is not running. (Exception from 
HRESULT: 0x8007016A)
At line:1 char:1
+ Import-Module Az.ContainerRegistry
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Import-Module], FileLoadException
    + FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportM 
   oduleCommand

I am not an expert in Powershell. Please help.

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,906 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. A M ANISUL HUQ 0 Reputation points
    2025-03-31T06:47:20.6833333+00:00

    My research has shown that this is a known problem with OneDrive. When the

    C:\.......\OneDrive\Documents\WindowsPowerShell\Modules\ folder is stored in OneDrive then you must make sure that all files in the Documents\PowerShell and Documents\WindowsPowerShell folders are marked as Always keep on this device. Doing so has resulted in the removal of the error.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.