private/Test-PwshPSHome.ps1

function Test-PwshPSHome {
    <#
    .SYNOPSIS
        Tests whether PSHOME is outside the WindowsApps directory
 
    .DESCRIPTION
        Checks whether PSHOME contains a WindowsApps path segment. Returns
        $false and writes a warning when it does, indicating that the module
        requires an MSI installation of PowerShell 7 for DISM operations.
        Returns $true without writing a warning for other PSHOME paths.
 
    .EXAMPLE
        PS> Test-PwshPSHome
 
        Tests whether the current PowerShell home is outside WindowsApps.
 
    .INPUTS
        None. This function does not accept pipeline input.
 
    .OUTPUTS
        System.Boolean. Returns $false when PSHOME contains a WindowsApps path
        segment; otherwise, returns $true.
 
    .NOTES
        Author: David Segura
        Company: Recast Software
        Version: 1.0.0
        Date: 2026-08-28
 
    .LINK
        https://aka.ms/powershell
    #>

    [OutputType([bool])]
    param ()

    if ($PSHOME -like '*\WindowsApps\*') {
        Write-Warning "[$(Get-Date -Format s)] This module requires the MSI installation of PowerShell 7. The MSIX (Microsoft Store) and WinGet installations of PowerShell run in a virtualized app container and do not support PowerShell DISM operations. Install PowerShell 7 from an MSI at https://aka.ms/powershell and try again."
        return $false
    }

    return $true
}