Context
I've just installed PowerShell 7. I am trying to run my working tested Azure related scripts... So I installed and imported AzureAd and AzureRM modules.
When trying to log in either Connect-AzureAD or Connect-AzureRmAccountboth gave me the following error (keep reading)
Could not load type 'System.Security.Cryptography.SHA256Cng'
OK, this is because the Azure Modules are looking for that API, which is not available in .NET Core, so I used the Import-Module with the -UseWindowsPowerShell parameter, which solved the issue but only for the AzureAD module
Question
For the command Import-Module AzureRm -UseWindowsPowerShell I got the following error message:
Import-Module: Failed to generate proxies for remote module 'AzureRM'. Running the Get-Command command in a remote session returned no results.
So I still can not use Connect-AzureRmAccount Any ideas?
The AzureRm is incompatible with PowerShell 7, and it has been deprecated and will not be updated.
Your option is to use the Az module, just uninstall the AzureRm module and install the Az module.
Install-Module -Name Az -Force
Fore more details, see Introducing the new Azure PowerShell Az module.
Then use the Connect-AzAccount to login, if you don't want to change your existing script which uses AzureRm command, just use Enable-AzureRmAlias before all the commands.
Related
I am trying to run a powerhsell script (my_script). The script is stored in this_folder on the desktop. I am executing the command at the the correct path by using C:\Users\me\desktop\this_folder> .\my_script. When I try to do this I get the error
The term 'Add-AzureRmAccount' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again
I know that the Add-AzureRmAccount is a part of the AzureRM.Profile module. When I got to the modules folder, I see that AzureRM.Profile is listed. To get these modules, I ran Install-Module -name AzureRM and Import-module AzureRM.
Any ideas what might be going on?
---Update---
When I ran Get-Module commands I saw that only that AzureRM module was listed. I thne tried to run Install-Module -Name AzureRM.Profile and got the error:
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
Since I see the AzureRM.Profile folder with a nupkg at one of the paths listed by $env:PSModulePath I thought I could just run Import-Module -Name AzureRM.Profile and I get the error
import-module : The specified module 'AzureRM.Profile' was not
loaded because no valid module file was found in any module directory.
Any ideas?
You say that you've installed and imported the AzureRM module, but have you connected the Azure account with the Connect-AzureRmAccount cmdlet?
I know a number of other modules does not expose all of the available cmdlets until there is an active connection to an account/subscription.
Be aware that scripts can ignore the context in which they are run so you might need to add the following to the start of the script:
Import-Module AzureRM
Connect-AzureRmAccount
Rather than running them manually in the console and then running the script.
You might want also want to look at using the Az module instead as the AzureRM module is being retired, and will only get bug-fixes till the end of December 2020: Introducing the new Azure PowerShell Az module
I am failing to use the SharePointPnpPowerShellOnline PS Module as part of my release pipeline.
We are using Azure DevOps with a hosted build agent on a Azure VM. I want to accomplish uploading build artifacts into Microsoft Teams/Sharepoint.
I installed SharePointPnpPowerShellOnline on the server (under the account that the DevOps build agent operates with), yet the build agent fails to execute the script on the first line that uses said module (a call to Connect-PnPOnline -Url https://... -Credentials ...). Error message: "Connect-PnPOnline : The term 'Connect-PnPOnline' is not recognized as the name of a cmdlet, function, script file". So it behaves as if the module is not installed at all.
yet when I log onto the server (with the correct account), the module is found and I can execute Connect-PnPOnline succesfully.
the used Azure DevOps pipeline task is "PowerShell".
Shouldn't the build agent be able to find the installed module, as I installed it for its user?
Edit: I did some more "debugging", namely:
logging the Username the script is running under by [Environment]::UserName, to make sure I installed the module for the right user. result: matches the expected user.
Listing the installed modules by Get-InstalledModule in my script. Once it is executed in the Release pipeline by the agent it yields an empty list. yet executing the same script on the VM (via RemoteDesktop) yields the installed modules
My guess is I'm doing a stupid beginner mistake because I haven't that much experience with PowerShell...
Answering my own question: In the end I just installed the Module again as part of the script by prepending the following two lines. Of course I'd be happy if somebody could explain why it didn't work the other way...
Install-PackageProvider Nuget -ForceBootstrap -Force
Install-Module -Name SharePointPnPPowerShellOnline -Force -Verbose -Scope CurrentUser
I have an Azure Release Pipeline with an Azure Powershell Task inline script that fails. I am running a self hosted build agent. The Powershell command works fine when I execute it locally from Windows Powershell. The task is attempting to start a DataFactory SSIS Integration Runtime:
Start-AzDataFactoryV2IntegrationRuntime -ResourceGroupName "MyResourceGroup"
-DataFactoryName "my-data-factory"
-Name "myIntegrationRuntime1"
-Force
Firstly I get a warning:
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot
be imported in the same session or used in the same script or runbook.
If you are running PowerShell in an environment you control you can
use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from
your machine. If you are running in Azure Automation, take care that
none of your runbooks import both Az and AzureRM modules. More
information can be found here: https://aka.ms/azps-migration-guide.
And then the error:
The 'Start-AzDataFactoryV2IntegrationRuntime' command was found in the
module 'Az.DataFactory', but the module could not be loaded. For more
information, run 'Import-Module Az.DataFactory'.
When I look at the installed modules, I see both AzureRM and Az are installed, and although I run the command Import-Module Az.DataFactory I do not see it in the list of installed modules.
WARNING: AzureRM.Profile already loaded. Az and AzureRM modules cannot
be imported in the same session or used in the same script or runbook.
From last year, Az published as a new cross-platform PowerShell module that is completely independent of AzureRM. Since Az and AzureRM use the same dependencies with different versions, it's impossible to run Az and AzureRM side by side in the same PowerShell session. That's why you receive the first error message.
The first solution is remove all AzureRM modules if you don't have script that use AzureRM.
But, if you continue want to use AzureRM for part of scripts while also writing another scripts with Az. You can execute with Azure Powershell task V4.0.
We are trying to extract Azure Advisor recommendations using PowerShell.
Unfortunately, Advisor doesnt seem to have an RM module.
Hence relying on DevOps Azure Task version 4.* which supposedly is for Az modules.
However, it appears that RM modules still gets loaded into the session per error below:
##[warning]Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found here: https://aka.ms/azps-migration-guide
Hence I am resorting to using Uninstall-AzureRM command.
##[error]Could not find a part of the path 'C:\Users\VssAdministrator\Documents\WindowsPowerShell\Modules'.
This is more or less what I am trying.
uninstall-azurerm
install-Module Az -force -scope currentuser
install-Module Az.Advisor -force -scope currentuser
import-module Az.Advisor
Get-AzAdvisor recommendations
Any help is appreciated either using RM or Az modules.
I'm trying to use a template to deploy an ASE. I can't use the UI since they made it clear that you can't deploy to a pre-existing subnet in the portal, but you can by using a PS template.
I run the script and it prompts New-AzureRmResourceGroupDeployment : Run Login-AzureRmAccount to login.
But I've logged in.
After researching I've tried
1. Uninstalling AzureRM and re-installing
2. Running update-module and updating
Problem with your the error message is:
Login-AzureRMAccount is available with different modules.
For eg if you are using azureRM module cmdlets you should probably login with:
AzureRM.profile\Login-AzureRmAccount
Have you select the right subscription?
We can use this PowerShell command to select subscription Select-AzureRmSubscription -SubscriptionName.
Also, we should check the version of your Azure PowerShell with this command Get-Module -ListAvailable -Name Azure -Refresh, the latest version is 3.9.0. Please try other commands to make sure the Azure PowerShell works fine.