Need to check below:
- Check that the Azure CLI tools extension is properly installed in Visual Studio Code. When the extensions fail in the middle, the az command will stop working.
- Go to settings and search terminal integrated shell as shown below. Check that the shell integration is enabled and the specific shell you've chosen is compatible with the Azure CLI versions.

After a workaround on this issue, I found a way to run CLI files in the Visual Studio Code by activating the "virtual environment".
Detailed steps given here for the Virtual env activation.
Once it is activated, install the Azure CLI
package using pip
.
pip install azure-cli

Once the installation done successfully, I created a file with the .azcli
extension and executed it by going to command palette -> search for run line in terminal
. It worked for me as expected.

To leave your virtual environment, use the deactivate
command in the terminal.
If still the issue persists, restart & update the Vscode for the better functionality.