How to automatically load PowerShell modules
This article explains how PowerShell modules are automatically loaded in Windows PowerShell and how that behavior applies when working with Cayosoft Administrator.
Since PowerShell 3.0, modules are automatically imported the first time a cmdlet from the module is used, as long as the module is located in a directory listed in the $Env:PSModulePath environment variable.
For more technical details, see the official Microsoft documentation: About Modules - PowerShell | Microsoft Learn.
PowerShell modules in the context of Cayosoft Administrator
When writing custom PowerShell scripts or using advanced rules in Cayosoft Administrator (e.g., Rules with script expressions or actions), you may need to use external PowerShell modules.
Commonly used modules include:
AzureAD – For Azure Active Directory management
Microsoft.Graph – For newer Microsoft 365 automation using Microsoft Graph
ExchangeOnlineManagement – For Exchange Online PowerShell
ActiveDirectory – For on-prem AD management (requires RSAT)
CayosoftCmdlets – Cayosoft's own module (automatically available in script contexts)
Module auto-loading requirements
For automatic import to work reliably:
The module must be installed correctly.
It must be located in one of the directories specified by the $Env:PSModulePath environment variable.
-
You can check this by running:
Copy$Env:PSModulePath -split ';' The module must include a
.psd1or.psm1manifest or script file.
If the module is not in one of the defined paths, you can:
Move or install the module to a valid path
Or manually import it in your script using
Import-Module
Example: using a module in Cayosoft rule script
# Example script that relies on the ActiveDirectory module
Import-Module ActiveDirectory
$user = Get-ADUser -Identity $TargetDN
$user.DisplayNameIf ActiveDirectory is in a valid PSModulePath folder, Import-Module is optional.
Comments
0 comments
Please sign in to leave a comment.