You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-reference-powershell.md
+22-23Lines changed: 22 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -402,14 +402,18 @@ You can see the current version by printing `$PSVersionTable` from any function.
402
402
403
403
## Dependency management
404
404
405
-
PowerShell functions support managing Azure modules by the service. By modifying the host.json and setting the managedDependency enabled property to true, the requirements.psd1 file will be processed. The latest Azure modules will be automatically downloaded and made available to the function.
405
+
PowerShell functions support downloading and managing [PowerShell gallery](https://www.powershellgallery.com) modules by the service. By modifying the host.json and setting the managedDependency enabled property to true, the requirements.psd1 file will be processed. The specified modules will be automatically downloaded and made available to the function.
406
+
407
+
The maximum number of modules currently supported is 10. The supported syntax is MajorNumber.* or exact module version as shown below. The Azure Az module is included by default when a new PowerShell function app is created.
408
+
409
+
The language worker will pick up any updated modules on a restart.
406
410
407
411
host.json
408
412
```json
409
413
{
410
-
"managedDependency": {
411
-
"enabled": true
412
-
}
414
+
"managedDependency": {
415
+
"enabled": true
416
+
}
413
417
}
414
418
```
415
419
@@ -418,10 +422,11 @@ requirements.psd1
418
422
```powershell
419
423
@{
420
424
Az = '1.*'
425
+
SqlServer = '21.1.18147'
421
426
}
422
427
```
423
428
424
-
Leveraging your own custom modules or modules from the [PowerShell Gallery](https://powershellgallery.com)is a little different than how you would do it normally.
429
+
Leveraging your own custom modules is a little different than how you would do it normally.
425
430
426
431
When you install the module on your local machine, it goes in one of the globally available folders in your `$env:PSModulePath`. Since your function runs in Azure, you won't have access to the modules installed on your machine. This requires that the `$env:PSModulePath` for a PowerShell function app differs from `$env:PSModulePath` in a regular PowerShell script.
427
432
@@ -432,28 +437,32 @@ In Functions, `PSModulePath` contains two paths:
432
437
433
438
### Function app-level `Modules` folder
434
439
435
-
To use custom modules or PowerShell modules from the PowerShell Gallery, you can place modules on which your functions depend in a `Modules` folder. From this folder, modules are automatically available to the functions runtime. Any function in the function app can use these modules.
440
+
To use custom modules, you can place modules on which your functions depend in a `Modules` folder. From this folder, modules are automatically available to the functions runtime. Any function in the function app can use these modules.
436
441
437
-
To take advantage of this feature, create a `Modules` folder in the root of your function app. Save the modules you want to use in your functions in this location.
442
+
> [!NOTE]
443
+
> Modules specified in the requirements.psd1 file are automatically downloaded and included in the path so you don't need to include them in the modules folder. These are stored locally in the $env:LOCALAPPDATA/AzureFunctions folder and in the /data/ManagedDependencies folder when run in the cloud.
444
+
445
+
To take advantage of the custom module feature, create a `Modules` folder in the root of your function app. Copy the modules you want to use in your functions to this location.
Use `Save-Module` to save all of the modules your functions use, or copy your own custom modules to the `Modules` folder. With a Modules folder, your function app should have the following folder structure:
452
+
With a Modules folder, your function app should have the following folder structure:
445
453
446
454
```
447
455
PSFunctionApp
448
456
| - MyFunction
449
457
| | - run.ps1
450
458
| | - function.json
451
459
| - Modules
452
-
| | - MyGalleryModule
453
-
| | - MyOtherGalleryModule
454
-
| | - MyCustomModule.psm1
460
+
| | - MyCustomModule
461
+
| | - MyOtherCustomModule
462
+
| | - MySpecialModule.psm1
455
463
| - local.settings.json
456
464
| - host.json
465
+
| - requirements.psd1
457
466
```
458
467
459
468
When you start your function app, the PowerShell language worker adds this `Modules` folder to the `$env:PSModulePath` so that you can rely on module autoloading just as you would in a regular PowerShell script.
@@ -502,17 +511,7 @@ You set this environment variable in the [app settings](functions-app-settings.m
502
511
503
512
### Considerations for using concurrency
504
513
505
-
PowerShell is a _single threaded_ scripting language by default. However, concurrency can be added by using multiple PowerShell runspaces in the same process. This feature is how the Azure Functions PowerShell runtime works.
506
-
507
-
There are some drawbacks with this approach.
508
-
509
-
#### Concurrency is only as good as the machine it's running on
510
-
511
-
If your function app is running on an [App Service plan](functions-scale.md#app-service-plan) that only supports a single core, then concurrency won't help much. That's because there are no additional cores to help balance the load. In this case, performance can vary when the single core has to context-switch between runspaces.
512
-
513
-
The [Consumption plan](functions-scale.md#consumption-plan) runs using only one core, so you can't leverage concurrency. If you want to take full advantage of concurrency, instead deploy your functions to a function app running on a dedicated App Service plan with sufficient cores.
514
-
515
-
#### Azure PowerShell state
514
+
PowerShell is a _single threaded_ scripting language by default. However, concurrency can be added by using multiple PowerShell runspaces in the same process. The amount of runspaces created will match the PSWorkerInProcConcurrencyUpperBound application setting. The throughput will be impacted by the amount of CPU and memory available in the selected plan.
516
515
517
516
Azure PowerShell uses some _process-level_ contexts and state to help save you from excess typing. However, if you turn on concurrency in your function app and invoke actions that change state, you could end up with race conditions. These race conditions are difficult to debug because one invocation relies on a certain state and the other invocation changed the state.
0 commit comments