Import-Module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory

Recently we have started configuring the Tfs build for continuous delivery for cloud services in Azure. I have followed the steps mentioned in the following article
cloud services continuous delivery

I have downloaded the PublishCloudService.ps1 file from the above article and added it to my project. I just reference this file in Post-build script path so that the powershell script will be excuted after the build has completed. I also passed the parameters required to the script thorugh Post-build script arguments.

After following all the steps mentioned in the above article , i queued my build. But my build was partially completed by showing the following error.
Import-Module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory.

When i check the PublishCloudService.ps1 powershell file given in the above article, i got to know that the error "Import-Module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory" occured at the following command

Import-Module Azure

The reason for the error is, The system was not able to find the Azurepowershell module path.

Solution:

Open PublishCloudService.ps1 file and search for the command Import-Module Azure. Now add the following line just above this command

$env:PSModulePath=$env:PSModulePath+";"+"C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell"

After adding the above line just save the file and queue the build again.I hope this will solve the error.

In this way we can fix the issue Import-Module : The specified module 'Azure' was not loaded because no valid module file was found in any module directory.
Read more...