Install an Integration Module from Azure Automation onto a VM - azure

I have a VM custom script extension that uses AzureRM.Storage cmdlets. When run, the script fails because it does not recognize the functions. Specificially, this error:
CommandNotFoundException Set-AzureStorageBlobContent : The term
'Set-AzureStorageBlobContent' 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.
The solution is simple. I need to Install-Module AzureRM.Storage on the VM. The problem is that I am working in an environment that should not install from the PowerShell Gallery (or the internet). I need the source to be the list of Integration Modules in my Azure Automation account.
In my DSC's, this is handled for me. I can Import-DSCResource and it will reach out to the Automation modules and install them in the local module root. How can I do this with a custom script extension? I have a DSC the runs before the script extension, so could install the module there but have not found a way yet. The following does not work as it seems the module is only installed once used, not on import.
Import-DSCResource -ModuleName AzureRM.Storage

Related

Powershell script execution from node js fails

I have a list of Powershell scripts that we've developed for a system administration. These scripts are called/executed from a Node JS application using "child_process" module. Everything works fine on my laptop. After transferring Node JS application to Centos7 server I'm receiving errors like this one:
The term 'Connect-VIServer' 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've checked Powershell execution policy - everything is set to Unrestricted. I can execute the same scripts from the command line without any error after I ssh to the server as a root user. The only difference I see is that Node JS application is running using a different user.
Found the problem - all modules were installed under /root/.local/share/powershell/Modules directory and nothing was installed under the user's profile that runs Node JS application. Copied all modules under app user directory /home/ndjs/.local/share/powershell/Modules/ and everything work now.

Error in Powershell Azure calls from Jenkins but not Powershell ISE?

I run the following in PowerShell ISE Connect-AzAccount and it works fine , but within Jenkins when run as a Powershell command I get the following error:
The term 'Connect-AzAccount' 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.
Why would this happen ?
Couple of things to try out:
You do not install AZ and Azure RM side by side , if you have it in the machine , please uninstall the Azure RM
Please try running the following command in order:
Install-Module Az
Import-Module Az
Connect-AzAccount
Additional reference:
https://learn.microsoft.com/en-us/azure/jenkins/execute-cli-jenkins-pipeline
Using Azure CLI in Jenkins pipeline
https://wiki.jenkins.io/display/JENKINS/Azure+CLI+Plugin
Hope it helps.

can't install module Azsk CI / CD pipeline when azure devops is installing the module

I have Azsk implemented in my azure devops pipeline. Before anything works finely and i can run the pipeline normally. i didn't changed anything but it gave me this error atm
2018-12-14T10:41:12.7861566Z Installing Module AzSK...
2018-12-14T10:41:58.9483761Z ##[error]Cannot process argument transformation on parameter 'InstalledModuleInfo'. Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Management.Automation.PSModuleInfo".
2018-12-14T10:41:58.9850394Z ##[section]Finishing: AzSK_SVTs
Google got me to this : https://github.com/Azure/azure-cli/issues/2357
But this will update the module on my local machine, while the problem is the installation of the module in my pipeline (some kind of container that azure devops is running).
Anyone have this issue lately or does know how to fix this ?
From the official Azsk GitHub:
Error message: "PackageManagement\Install-Package: cannot process argument transformation on parameter 'InstalledModuleInfo'..."
If you have installed AzureRM PowerShell using Azure SDK in your machine, it typically get installed in Program Files. You could run the below command to confirm
Get-Module -Name AzureRM* -ListAvailable
If this is the case, then you need to remove the Azure PowerShell modules installed through Azure SDK completely from the Program Files. You could also take back up in case if you need. AzSK also need AzureRM modules. But it would download from PSGallery instead of from Azure SDK. This downloading of AzureRM modules from PS Gallery would conflict with AzureRM modules installed through Azure SDK. After cleanup, If you again the run the below command, it would fetch AzureRM version 5.2.0 by default into the current user scope instead of in Program Files.
Install-Module AzSK -Scope CurrentUser -AllowClobber
In case you still need to use the other version of AzureRm (that you removed), you can install it from PS Gallery using the command below:
Install-Module AzureRM -Scope CurrentUser -AllowClobber -RequiredVersion <versionNumber e.g. “3.8.0” >
Note: If "-AllowClobber" option is not available in your version of PS, then replace that with "-Force"
If you happen to have multiple versions of AzureRM, then it depends on which version of the module loads first in the PS session. In that case, to avoid confusion, close the installer PS session and in a new PS session run the following first:
Import-Module AzSK
Then you can run one or more AzSK commands or other AzureRm commands. The "Import-Module" ensures that the right version of AzureRM gets loaded into the current session.
So in your case that is Hosted agent, try add PowerShell task before the Azsk task and run the commands above.

The term 'New-AzureRmServiceBusNamespace' is not recognized as the name of a cmdlet, function, script file, or operable program

I was getting below error
The term 'New-AzureRmServiceBusNamespace' is not recognized as the name of a cmdlet, function, script file, or operable program.
If i try to run Import-Module AzureRM.ServiceBus I get below error
The member 'FormatsToProcess' in the module manifest is not valid: Cannot find path 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.ServiceBus.\Microsoft.Azure.Commands.ServiceBus.format.ps1xml' because it does not exist.. Please make sure that a valid value is specified for this field in file 'C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager\AzureRM.ServiceBus\AzureRM.ServiceBus.psd1'.
As suggested on Error loading azure.profile in 1.0.5, I reinstalled azure PowerShell using "Install-Module AzureRM -Verbose -Force". After that New-AzureRmServiceBusNamespace is identified but getting below error
"The term 'Login-AzureRmAccount' is not recognized as the name of a cmdlet, function, script file, or operable program.".
The solution to fix this error is reinstalling Azure PowerShell by using MSI. After that Login-AzureRmAccount is identified but New-AzureRmServiceBusNamespace goes missing again. I'm going in circles.
I've to make New-AzureRmServiceBusNamespace work without breaking Login-AzureRmAccount. Please help me.
Please check your Azure PowerShell version firstly, you could use the following cmdlet.
Get-Module -ListAvailable -Name Azure -Refresh
My version is 3.6.0. New-AzureRmServiceBusNamespace and Login-AzureRmAccount all work for me. If your version is not latest, I suggest you could update your version to latest. You can download the PS version 3.6.0 installation file from this link.
Update from comment:
When OP upgrade his laptop from Windows 7 to Windows 10, it works fine.
I would remove the Azure powershell that was installed by msi (completely) and reboot, after that I'd check C:\Program Files\WindowsPowerShell\Modules directory and delete all Azure related modules from there. After that, I'd do Install-Module AzureRM

New-SCWebDeployPackage is not recognized

I'm trying to package a Sitecore solution and followed the instructions mentioned in the following URLs.
https://doc.sitecore.net/cloud/working_with_sitecore_azure/configuring_sitecore_azure/getting_started_with_sitecore_azure_toolkit?roles=developer
https://doc.sitecore.net/cloud/working_with_sitecore_azure/configuring_sitecore_azure/package_a_sitecore_solution_for_the_azure_app_service?roles=developer
I have PowerShell (5.0). I have also updated Azure PowerShell Module 3.1.0
When I run the command Start-SitecoreAzurePackaging with all the options specified in the Sitecore documentation, I get the following error.
The term 'New-SCWebDeployPackage' 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.
Am I missing something?
Thanks,
Prawin
run the below line before you run the command.
Import-Module [your path]\Cloud.Services.Provisioning.SDK\tools\Sitecore.Cloud.CmdLets.dll

Resources