If every az
command fails in PowerShell with a Python traceback ending in
ImportError: DLL load failed while importing win32file
This error appeared for many Windows users after updating Azure CLI to v2.77.0. The problem lies inside the bundled Python runtime, not your system’s Python.

Why Azure CLI Commands Fail
Starting with v2.77.0, Microsoft’s Azure CLI for Windows ships with an embedded Python runtime. In this release, one of the critical libraries (pywin32
, which provides access to Windows file APIs) failed to load correctly.
When Azure CLI tries to initialize telemetry via portalocker
, the win32file
module triggers an ImportError. Because the failure occurs during startup, every az
command—no matter which one—crashes before execution.
So, it’s not your environment or your PowerShell—it’s the CLI build itself.
Fix: Azure CLI DLL load failed win32file
1. Uninstall the Broken Version
Remove Azure CLI completely:
- Open Settings → Apps → Installed Apps.
- Uninstall Microsoft Azure CLI.
- Manually delete any leftover folder:
C:\Program Files\Microsoft SDKs\Azure\CLI2
or
C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2
2. Reinstall the Last Stable Version (2.76.0)
There are two safe ways to do this:
Option A – Download MSI directly
https://azcliprod.blob.core.windows.net/msi/azure-cli-2.76.0-x64.msi
Run the installer and follow the prompts.
Option B – Use Winget (if the version is still available)
winget uninstall --id Microsoft.AzureCLI -e
winget install --id Microsoft.AzureCLI -e --version 2.76.0
3. Verify Installation
After reinstalling:
az --version
You should now see version 2.76.0 and no Python error.
4. Optional Sanity Checks
- Ensure PYTHONHOME and PYTHONPATH are not set in environment variables.
- Whitelist the Azure CLI directory in your antivirus (some tools quarantine
pywin32
DLLs). - Restart PowerShell to clear any cached sessions.
5. When Microsoft Releases the Fix
Keep an eye on Azure CLI release notes or GitHub issues. Once a newer version (2.77.x or 2.78) mentions “Windows DLL fix,” update safely:
az upgrade
or reinstall using the same MSI URL pattern (replace the version number).
Temporary Workaround: Use Azure Cloud Shell
If you need az
immediately and can’t reinstall, open Azure Cloud Shell.
It runs a fully functional Azure CLI inside your browser, isolated from your local environment, and is unaffected by this Windows bug.
Read More:
- ServerFarmCreationNotAllowed Azure Fix: Unable to Create App Service Plan
- Fix: Azure VM Not Accessible After Switching to Standard SKU Public IP
- How to Add Azure Monitor Active Alerts Count to App Insights Dashboard
- How to Add Dev Team and Resources to Azure Dev and Prod Environment
How to Prevent Similar CLI Issues
To avoid breakages in future updates:
- Pin versions in CI/CD pipelines instead of running
az upgrade
blindly. - Test new builds in a sandbox before rolling them into production scripts.
- Keep a local backup of a stable MSI (like 2.76.0) for rollback.
This approach ensures your automation isn’t at the mercy of an unexpected regression.