When working with Power Platform environments and their components, having these required PowerShell modules installed at least is crucial. The modules required to get started with are:
This list is not exhaustive and you may add more modules here as required in case you are working with other services like Azure, Excel, etc. Ensuring these modules are present on your development system simplifies your workflow and avoids unnecessary delays.
This PowerShell script automates the process of checking and installing the required modules. It ensures developers can get started quickly without needing to comb through documentation or install modules one by one.
# Function to check if a module is installed
function Check-Module {
param (
[string]$ModuleName
)
# Check if the module is available
$module = Get-Module -ListAvailable -Name $ModuleName -ErrorAction SilentlyContinue
return $null -ne $module
}
# Function to install a module
function Install-ModuleIfNotInstalled {
param (
[string]$ModuleName
)
if (Check-Module -ModuleName $ModuleName) {
Write-Host "$ModuleName is already installed." -ForegroundColor Green
} else {
Write-Host "$ModuleName is not installed. Installing now..." -ForegroundColor Yellow
try {
Install-Module -Name $ModuleName -Force -Scope CurrentUser -AllowClobber -ErrorAction Stop
Write-Host "$ModuleName has been successfully installed." -ForegroundColor Green
} catch {
Write-Host "Failed to install $ModuleName. Error: $_" -ForegroundColor Red
}
}
}
#Main Script Starts
# List of modules to check and install
$modules = @(
"Microsoft.PowerApps.Administration.PowerShell",
"Microsoft.PowerApps.PowerShell",
"Microsoft.xrm.Data.PowerShell",
"Microsoft.Xrm.Tooling.CrmConnector.PowerShell"
)
# Iterate through each module and check/install it
foreach ($module in $modules) {
Install-ModuleIfNotInstalled -ModuleName $module
}
#Main Script Ends
Check-Module
Function:
Get-Module -ListAvailable
.true
if the module exists; otherwise, false
.Install-ModuleIfNotInstalled
Function:
Check-Module
.Install-Module
.Install-ModuleIfNotInstalled
for each one.-Scope CurrentUser
), ensuring no administrative privileges are required.-Force
flag ensures updates if the module already exists in a different version.If you come across the error message below while running the script, follow the next steps to resolve it.
Install Power Platform PowerShell modules.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : SecurityError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
Open another instance of PowerShell ISE as Administrator then execute the below command:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
You may use other Execution Policy which will allow to run custom scripts like ByPass etc depending on the privilege you have. Once this command is successfully executed, you can close this instance and continue with the module installation.
Check James Yumnam’s original post https://jamesyumnam.com/2025/01/08/automate-powershell-modules-installation-for-power-platform/ on jamesyumnam.com which was published 2025-01-08 09:32:00