This PowerShell module helps you to create local files for easy start with Azure Functions. See How to Use section below for a quick start.
If you already have your Azure Function created (or you know how to do it), then just run New-AzFC <MyCommand>
and upload generated files to your function! Simple as that!
Command will generate two files:
- index.html - simple web page that enables you to enter input values for commandlet parameters (left/first page in screenshots below)
- run.ps1 - actual script that is executed inside of Azure Function
- without parameters it returns index.html
- with parameters, it executes specified command on web server and returns result (right/second page in screenshots below)
Module is tested on both Windows PowerShell and on PowerShell Core.
If you want to learn how PowerShell Azure Function works, check auto-generated run.ps1 files under Examples folders. For more information on getting started with Azure Functions, check this introduction page.
You can install this module from PowerShell Gallery (preferred way) or by cloning GitHub repository. Module is tested both on Windows PowerShell and PowerShell Core.
Find-Module EasyAzureFunction -Repository PSGallery | Install-Module -Scope CurrentUser -Force
git clone https://github.com/iricigor/EasyAzureFunction.git # Clone this repository
Import-Module .\EasyAzureFunction\EasyAzureFunction.psd1 -Force # Import module
In order to fully use this module, you need have Azure function and do two simple steps. Azure Function should be HTTP triggered PowerShell function. Check more info here.
New-AzureFunctionCode -Command Get-Process -Path C:\GP
You can select any PowerShell command instead of Get-Process. You will get two files in folder: run.ps1 and index.html.
In AzF you created, replace content of default 'run.ps1' with the one you created. Under files section (far right), click on Add and create new file named 'index.html' and replace its content also.
Advanced users can do these actions also via FTP.
Module publishes two new commandlets:
- New-AzureFunctionCode (alias New-AzFC) - which generates mentioned files
- Get-Parameter - which lists all parameters for a given command or script
Here are some basic examples for built in PowerShell commands. All of these links will open Azure Functions web page, so just click it and see it in action.
- Get-Command - type
Pester
as value for parameter-Module
- Get-Process - run without any parameters to see all visible processes
- Get-Module - select
-ListAvailable
and addPester,Dism
in Name field under it
And here are some examples using non-Get functions
- Write-Output - try to create 'Hello world!' example
- Hello-World - created with -PreCode parameter, see Examples/HW folder
- Set-ExecutionPolicy - shows usage od drop downs in html page, also it helps to understand restrictions on Azure Function environment
- Lorem-Ipsum.ps1 - this shows that module can be used also with custom script (*.ps1), see additional comments on that commandlet parameter
- Invoke-Command - this example demonstrate usage of PSCredential objects in input web page.
- Generated html file only supports strings in input fields. If a command expects certain complex object (i.e. PSCredentials, PSSession, etc.), it will fail
- Generated html does only basic parsing of arrays (split on comma), so it might not work always as expected
- Tobias @TobiasPSP for great and inspiring conference PSConfEU 2018
- Sergei @xvorsx for nice introduction to PlatyPS
- Jakub @nohwnd for great testing framework Pester
- Aleksandar @alexandair - for great social component at the PSConfEU conference
- The PowerShell team (Joey, Steve and others) - for great product!