Automate PowerShell Modules Installation for Power Platform

James YumnamPower Platform1 month ago14 Views

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:

  • Microsoft.PowerApps.Administration.PowerShell
  • Microsoft.PowerApps.PowerShell
  • Microsoft.xrm.Data.PowerShell
  • Microsoft.Xrm.Tooling.CrmConnector.PowerShell

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.

“Simply run this script, and it will take care of everything for you.”

The Script:

# 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

How it Works:

  1. Check-Module Function:
    • Checks if a specific module is available using Get-Module -ListAvailable.
    • Returns true if the module exists; otherwise, false.
  2. Install-ModuleIfNotInstalled Function:
    • Checks if the module is already installed using Check-Module.
    • If not installed, attempts to install it using Install-Module.
  3. Main Script:
    • Iterates through the list of modules and invokes Install-ModuleIfNotInstalled for each one.

Notes:

  • Scope: The modules are installed for the current user (-Scope CurrentUser), ensuring no administrative privileges are required.
  • Force: The -Force flag ensures updates if the module already exists in a different version.
  • Error Handling: Catches and reports installation errors.

Troubleshooting Installation

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

Resolution:

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

Leave a reply

Join Us
  • X Network2.1K
  • LinkedIn3.8k
  • Bluesky0.5K
Support The Site
Events
March 2025
MTWTFSS
      1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
« Feb   Apr »
Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...