Upgrade AzureRM Powershell on Hosted 2017 Agent (VSTS - Visual Studio Team Services) : <p>I am using release management through Visual Studio Teams Services (online). We use Hosted build Agents and I really want to avoid the overhead of managing custom agents. </p>

<p>One item I do need is the AzureRM PowerShell module. Versions up to 5.1.1 are <a href="https://github.com/Microsoft/vsts-image-generation/blob/master/images/win/Vs2017-Server2016-Readme.md" rel="noreferrer">available on the agent</a> but I need 6.0.0. </p>

<p>What I would like to do is use a step in my release process (PowerShell) to aquire version 6.0.0 and use thart instead, however I cant quite get it to work. I have tried a few approaches that have all come unstuck, the current one is: </p>

<pre><code>Write-Output "------------------ Install package provider ------------------"
Find-PackageProvider -Name "NuGet" | Install-PackageProvider -Scope CurrentUser -Force

Write-Output "------------------ Remove Modules ------------------"
Get-Module -ListAvailable | Where-Object {$_.Name -like 'AzureRM*'} | Remove-Module

Write-Output "------------------ Install the AzureRM version we want - 6.0.1!  ------------------"
Install-Package AzureRM -RequiredVersion 6.0.1 -Scope CurrentUser -Force

Write-Output "------------------ Import AzureRM 6.0.1  ------------------"
Import-Module AzureRM -RequiredVersion 6.0.1
</code></pre>

<p>This all works fine (i.e. does not crash...) but then when I try and use one of the 6.0.1 cmdlets I get an error. </p>

<blockquote>
  <p>Get-AzureRmADGroup : The Azure PowerShell session has not been
  properly initialized.  Please import the module and try again.</p>
</blockquote>

<p>Any idea of where I am going wrong or alternate strategies I can use to deploy AzureRM 6.0.1 and use it on a hosted agent?</p>
