Search code examples
powershellazureazure-powershellsqlps

SQLPS/AzureRm.Profile modules stopped working on Azure VM image


I have a CI build process that's been working great for months. Despite having no changes, it suddenly broke and now consistently fails with this error:

The 'Backup-SqlDatabase' command was found in the module 'SQLPS', but the module could not be loaded. For more information, run 'Import-Module SQLPS'.

The process provisions a new VM every time so I'm guessing it has something to do with Microsoft updates but I can't tell what. Thus far, the only way I've been able to fix it is to log in through RDP to the newly provisioned VM before the CI process starts.

I tried adding Import-Module SQLPS to the build script and got an even weirder error message

Could not find file 'Microsoft.Azure.Commands.Profile.format.ps1xml'

I tried Install-Module SQLPS and got

No match was found for the specified search criteria and module name 'SQLPS'.

So I added

$modules = (Get-Module -Name "AzureRM" -Verbose)
$modules | Uninstall-Module -Force -Verbose
Install-Module AzureRM -Verbose -Force
Import-Module SQLPS

But am now getting a new error:

"The process cannot access the file 'C:\Program Files\WindowsPowerShell\Modules\AzureRM.profile\3.3.1\Hyak.Common.dll' because it is being used by another process."

I feel like I'm running in circles. Is this a Microsoft update or something? Can anyone tell me how to fix my AzureRM module which seems to me to be breaking my SQLPS module somehow?


Solution

  • I can't figure it out. I rewrote it to use sqlcmd and BACKUP DATABASE.