I want to use the following code in a Azure Function powershell app:
Add-AzTableRow `
-table outputTable`
-partitionKey $partitionKey `
-rowKey ($record.id) -property @{"userId" = "001";}
I’m using this documentation as a guide. However, this guide uses Install-Module AzTable
. Since I am using a Function App to run this code on a timer, I can’t install the module on run time. I’ve followed this question/answer. I’ve added this to `requirements.psd1′:
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
#'Az' = '8.*'
AzTable = '2.*'
}
When I run the code I get the following error:
[Error] ERROR: The 'Add-AzTableRow' command was found in the module 'AzTable', but the module could not be loaded. For more information, run 'Import-Module AzTable'.
Could someone please give me some insight on what I’m doing wrong? I want to be able to update and query the table from the Function App without any user input.
Edit:
I have added 'Az' = '8.*'
and 'AzTable' = '2.*'
. I let the function install the resource by running and waiting. I’m now getting the error:
[Error] ERROR: The term 'Add-AzTableRow' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
I’m not sure why I’m getting this error because Add-AzTableRow
is apart if the AzTable
module.
2
Answers
The AzTable module requires the Az Module:
It requires latest PowerShell Az module installed
https://www.powershellgallery.com/packages/AzTable/2.0.1
But currently the install of the Az module is disabled in your requirements.psd1:
Remove
#
from#'Az' = '8.*'
='Az' = '8.*'
After that the machine behind the function will install the required module and the code will be able to load it/acces the functions.
Note if you "activate" a module the first time, run your code and maybe you still get the error messge -> script got started before module install completed… so simply wait some minutes and retry.
run.ps1
requirements.psd1:
Result:
Note: If you are running the PowerShell Function with these modules for the first time, it will take some time during the runtime/execution.