Azure DevOps PowerShell task fails to load 'Az.CosmosDB' module - powershell

I have an Azure DevOps pipeline to rotate Cosmos DB account keys. To do this, I'm using PowerShell and the New-AzCosmosDBAccountKey cmdlet.
For some unknown reason, the Az.CosmosDB module is not installed with Az, so it needs to be installed manually each time the pipeline is run.
Install-Module -Name Az.CosmosDb -AllowClobber -Force
When I run this locally everything works as expected, but within Azure DevOps I see an error
The 'Get-AzCosmosDBAccountKey' command was found in the module 'Az.CosmosDB', but the module could not be loaded.
What might be happening in Azure DevOps that differs from what is happening locally?

The answer here is that an update was made to the Az.CosmosDb module so that it specifically requires version 1.9.4 (or higher) of Az.Accounts. However, on the Azure DevOps hosted agent they use version 1.9.3.
To fix, I changed the command that manually installs the Az.CosmosDb module -
Install-Module -Name Az.CosmosDb -RequiredVersion 0.1.6 -AllowClobber -Force
Note
When I found on the PowerShell Gallery that all versions of the Az.CosmosDb module were < 1.0.0 I did some investigation and it turns out that the module is still in preview, despite Cosmos DB having existed for years. This explains why the module is not installed along side all other Az.* modules when installing Az.
What is very frustrating is that there is no mention anywhere on the documentation for the module that it is in preview. If there were, it would probably have saved me a good chunk of time!

Please check when you run DevOps Pipeline, which agent pool you are using. If you use microsoft-hosted agent, each time you run a pipeline, you get a fresh virtual machine. The virtual machine is discarded after one use. So you need to install the Az.CosmosDB module manually each time.
You could also deploy an agent on your local machine, in this way, it's supposed not need to nstall the Az.CosmosDB module manually each time.
https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser

Seems today Azure DevOps finally broke everything, old variant with
Install-Module Az.CosmosDB -RequiredVersion 0.1.6 -Force
has stopped working. Amazing, the whole experience with Az DevOps and Azure technologies are pretty the same, each time they just suddenly have stopped working at random places!
UPD: The gallery source address is dead https://www.powershellgallery.com/packages/Az.CosmosDB/0.1.6 , looks that is the reason

Related

AzurePS System capability is not available on a newly installed vsts-agent

I have successfully installed a new VSTS agent on a new Azure VM - Windows Server 2012 R2 (64bit). When I am try to execute any pipelines containing azure powershell tasks on the new vsts agent, I get an error message :-
Error message 'No agent found in pool BuildAgent2 which satisfies the specified demands:azureps Agent.Version -gtVersion 2.119.1'
Is there any way to add AzurePS as a system capability ?
Please advise on the steps to do this - thanks.
AzurePS System capability is not available on a newly installed vsts-agent
Agree with jessehouwing.
If you want to enable AzurePS System capability, you could install the PowerShell 5.1 or higher on Windows, or PowerShell Core 6.x and later on all platforms, then install/update the Azure PowerShell module on the Azure VM:
Install the Azure PowerShell module
But the error you got should more related to the demands you set on the option tab of your build :
Check the agent version you have installed, make sure you set the correct version, or you can try to remove that demands to check if you still have this issue.
Hope this helps.
I got the same error using the AzureFileCopy#4 task in a self-hosted agent, but I solved it by installing the az module https://www.powershellgallery.com/packages/Az
Install-Module -Name Az

Deployment of Logic Apps Integration Account with PowerShell error

I use the powershell New-AzureRmIntegrationAccountSchema to deploy a schema to an integration account.
It worked in the past but now I have this error :
Unable to deserialize the response.
Unfortunately I don't have more details on the issue.
Any ideas?
I set the PowerShell version to 2.1.0 in the Release Pipeline and now it works :)
For your issue, I suggest you could test your xml file on Azure Portal to know whether this is a Power Shell issue or your xml issue.
If your xml works fine on Azure Portal. You could check your Azure Power Shell version with following cmdlet.
Get-Module -ListAvailable -Name Azure -Refresh
I test on 4.4.1 version, it works for me. You could download the msi installer from the link.
If it also does not work, you could add $DebugPreference="Continue" to print more debug log.
Update:
It is a Power Shell version issue, OP use older version Power Shell, when set the Power Shell version to 2.1.0, the issue is resolved. I test in my lab, if we use the latest version, the cmdlet also works.

Packer - Windows Server 2012R2 - Install PowerShell 5

I'm having trouble with installing PowerShell 5 on Windows Server 2012 R2 using Packer.
To install PowerShell 5.1, I'm using chocolatey
powershell
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
choco install PowerShell -y
I need to to do this for two packer builder:
Amazon Web Services EC2 AMI.
Hyper-V Vagrant.
With the Amazon Web Services EC2 AMI I've tried executing the above from the following locations
As part of the user_data_file script.
As an inline provision script.
I've added the windows-restart provision in the flow after the execution of the fragment.
Similarly I've tried the same with the Hyper-V Vagrant both as part of the Autounattend flow and as an inline provision.
In both cases the installation fails because the user profile is not created. At least I think that is the problem. As a reference, I've faced the exact same problem when installing sql server express.
Has anyone managed to accomplish this flow and what is your recommendation?
PowerShell package uses MSU (Windows Update file). There are a couple of considerations here:
Ensure Windows Updates Service is turned on. Chocolatey doesn't do that yet, although there is an issue filed.
MSUs must be run locally from the machine. So if you are running over WinRM, you instead need to have it set up a scheduled task to call choco install and then run it that way.
Yes, that second point is accurate. No, it is not Chocolatey's fault. That's a Microsoft design decision with MSU files. It's a real PITA.
FYI - BoxStarter handles it appropriately, and it can be used with Packer. You will find less pain if you look there.
HTH

How to deploy an msi from visual studio online to azure vm?

I have a build definition on visual studio online which creates an msi installation package using WiX.
How can I automatically deploy the msi package from VSO build agent to Azure VM after the build completes successfully?
Note: I prefer to use a post-build batch or powershell script as part of the build process. The script should copy the msi to the vm and install it.
You should use Release Management Online. It comes with VSO and allows you to easily orchestrate installing an MSI on any Azure server.
http://nakedalm.com/building-release-pipeline-release-management-visual-studio-2013/
Microsoft just added RM in VSO and its simple to use. I setup an end to end web app deployment, buy as its just a PowerShell to do the install an MSI would be trivial. RM takes care of getting all of the bits to the right spot...
http://nakedalm.com/create-release-management-pipeline-professional-developers/
Honestly, it sounds hard, but is much easier than trying to do it all yourself.

Is it possible to upgrade Azure Powershell (ISE) in Windows Server 2012 R2 without reinstalling?

I'm running Windows Server 2012 R2 in an Azure VM in which I have an older version of Azure Powershell (ISE) - when I run . I searched for instructions on how to update Azure Powershell (ISE) but all I'm finding is on how to install from scratch per http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/
Is there a way to upgrade without having to re-import the Azure subscription publish-settings file etc ?
By the way, an easy way to find out what version I'm on would be great. Doing get-module azure or get-module does not give me version info per http://cropme.ru/fc7037d19a74cd0db256c52142d9b98a
After you upgrade the Azure PowerShell module, you can just run Add-AzureAccount to update your subscription settings.