Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Azure Powershell Scripts in a Function #294

Closed
napalm684 opened this issue May 17, 2017 · 6 comments
Closed

Question: Azure Powershell Scripts in a Function #294

napalm684 opened this issue May 17, 2017 · 6 comments
Labels

Comments

@napalm684
Copy link

Random question, I know you can run powershell in an azure function. Is it possible to run "azure powershell" scripts via an azure function to spin up/down infrastructure. The question then becomes if it is possible how would one install azure powershell in the context of the azure function? Thanks in advance, hopefully this hasn't already been asked as I couldn't find it (if it was).

@tohling
Copy link

tohling commented May 17, 2017

Yes, here's an SO thread that walks through how that is done. http://stackoverflow.com/a/40883318/6465830

@napalm684
Copy link
Author

@tohling thank you for the response, it is my assumption that azure powershell is already installed for azure functions to utilize when you choose powershell as the function language?

@tohling
Copy link

tohling commented May 17, 2017

Yes, Azure PowerShell is already installed. You will be working with:

  1. PowerShell 4.0 - We are blocked on upgrading to PowerShell 5.0 as its installer does not install in our VMs. No ETA on this. If you need to use PowerShell 5.0, then Azure Functions will not be able to support this scenario at the moment.

  2. Azure PowerShell 1.4 - You can bring you own latest version of Azure PowerShell modules. Here are the steps to upload and use a different set of Azure PowerShell modules:

  • Using the Kudu console, create a new randomly named folder, e.g. azmodules either inside the Function folder or move it up the directory tree to be shared across Functions.
  • Upload the modules and all their dependencies to the azmodules folder.
  • Remove the modules folder (if it exists) from the Function.
  • In the Function’s implementation code, import the modules directly with the -Global parameter. e.g.
Import-Module "D:\home\site\wwwroot\azuremodules\AzureRM.Profile.psd1" -Global;
Import-Module "D:\home\site\wwwroot\azuremodules\AzureRM.Resources.psd1" -Global;
Import-Module "D:\home\site\wwwroot\azuremodules\AzureRM.Tags.psd1" -Global;

@napalm684
Copy link
Author

Awesome thanks again!

@lindydonna
Copy link
Contributor

Closing issue as question was answered

@mganeshphani
Copy link

mganeshphani commented Jun 7, 2018

@tohling @napalm684 I went ahead and used this approach to import complete suite of Azure RM into Azure functions by updating $env:psmodulepath to include "D:\home\site\wwwroot\azuremodules" within azure function and reference base(azurerm) psd1 file to import... this approach seemed inevitable and simplest to use all the modules of AzureRM.

Thankyou for raising this issue and providing some valuable comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants