Trying to use Connect-SPOService in Azure Function - azure

This works fine locally but not when I try to run it in an Azure function. I am assuming that I need to add it as a requirement in the requirements file as I have done with other modules? I spent the last half hour searching but could not figure out how to it this for this particular module (I've done it with others).
** Connect-SPOService -Url https://mycompany-admin.sharepoint.com -Credentials $cred
**
The term 'Connect-SPOService' is not recognized as the name of a cmdlet, function, script file, or operable program. >>

I'll have to do something similar. I haven't tried yet. But maybe, like I do remotely, you have to import the module first, with Windows Compatabilty Mode, since it's a Core PowerShell?
Import-Module -Name Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell

Related

ThreadJob module stopped working for seemingly no reason

I'm on Powershell 5.1 which IIRC supports ThreadJob OOB.
I have a script which uses the module which used to work without issues.
Now I'm getting the following error:
ForEach-Object : The term 'Start-ThreadJob' 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.
Admittedly I haven't run the script (or used ThreadJob) in a while, but I get the "not recognized" error even when I just call Start-ThreadJob from the terminal.
I've rebooted and run DISM and sfc which didn't find any issues.
This is on a fairly fresh Windows 10 install.
Am I forgetting something?
I vaguely recall experiencing something like this a long time ago, but don't remember how I got around it.
Windows PowerShell - the legacy, Windows-only, ships-with-Windows edition of PowerShell whose latest and last version is 5.1.x - does not come with the ThreadJob module that provides the Start-ThreadJob cmdlet - only the modern, cross-platform, install-on-demand PowerShell (Core) edition (v6+) does.
However, you can install the module on demand in Windows PowerShell, from the PowerShell Gallery, with Install-Module -Scope CurrentUser ThreadJob, for instance.
The following cross-edition idiom installs the module on demand when running in Windows PowerShell, in the scope of the current user:
if ($PSVersionTable.PSVersion -lt 6 -and -not (Get-Command -ErrorAction Ignore -Type Cmdlet Start-ThreadJob)) {
Write-Verbose "Installing module 'ThreadJob' on demand..."
Install-Module -ErrorAction Stop -Scope CurrentUser ThreadJob
}
# Getting here means that Start-ThreadJob is now available.
Get-Command -Type Cmdlet Start-ThreadJob

Which module is required for "Get-AzureRmWebApp"?

I am trying to run a powershell script with cmdlet Get-AzureRmWebApp but get the error
Get-AzureRmWebApp : The term 'Get-AzureRmWebApp' 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 have installed module Az and AzureRM which I thought will be the one, but no luck.
Is there any aother command after Install-Module -Name AzureRM that is required ?
thanks
Try
Install-Module -Name AzureRM.Websites
Refrence - https://learn.microsoft.com/en-us/powershell/module/azurerm.websites/?view=azurermps-6.13.0

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.

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

Created Powershell Azure function and trying to use "az" commands under that function app. As per docs, function runtime should resolve "az" and other module dependencies. but it doesn't work for me.
ERROR: The term 'az' 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.
Microsoft.Azure.WebJobs.Script.Rpc.RpcException : Result: ERROR: The term 'az' is not recognized as the name of a cmdlet, function, script file, or operable program.
I want to run some "az" command under function app without manually uploading modules. Is it powershell Preview version issue or something I need to correct?
requirement.psd1
#{
Az = '2.*'
}
For those who get these error in local while trying to access AZ, try this command below in an admin PowerShell instance.
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
You can get more details about installation # https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-powershell
Make sure you restart the powershell instance
"Az" in the context of PowerShell probably means the Az module, with cmdlets like Add-AzAccount etc.
"az" is the cross-platform CLI, which is not a PowerShell module.
I got this error because I had not installed CLI. I was sent this link which downloaded the required install:
https://aka.ms/installazurecliwindows
Two ways you can solve this issue.
Install below installation file for Azure CLI in windows.
https://aka.ms/installazurecliwindows
(OR)
Install using PowerShell the below command.
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'; rm .\AzureCLI.msi
More details: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli
I can see PowerShell 7.x and later is the recommended version.
You can check Powershell version using below command
$PSVersionTable.PSVersion
https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-6.2.0
NOTE
PowerShell 7.x and later is the recommended version of PowerShell for
use with the Azure Az PowerShell module on all platforms.
Run this to fix:
Install-Module AzureAD -Force
Install-module AzureADPreview -Force
Install-Module -Name MSOnline -Force
Import-Module Az -Force
Install-Module Az -Force
Download this then this problem will not occur.
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli

Install an Integration Module from Azure Automation onto a VM

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

Resources