Last active
March 26, 2024 19:39
-
-
Save blakedrumm/a902c31fd46a5a3c2385884a22392611 to your computer and use it in GitHub Desktop.
This grabs the Name, Version, Scope, and InstalledLocation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Blake Drumm ([email protected]) | |
# Created: March 26th, 2024 | |
# Retrieve PSModulePath | |
$modulePaths = $env:PSModulePath -split ';' | |
# Retrieve all installed modules | |
$installedModules = Get-Module -ListAvailable | |
if ($installedModules) { | |
$moduleInfo = @() | |
foreach ($moduleDetail in $installedModules) { | |
# Check if the module is installed for the current user, all users, or system | |
$modulePath = ($moduleDetail).ModuleBase | |
$version = ($moduleDetail).Version | |
$scope = switch -Wildcard ($modulePath) { | |
"$env:USERPROFILE*" { "Current User" } | |
"$env:ProgramFiles*" { "All Users" } | |
"$env:SystemRoot*" { "System" } | |
default { "Unknown" } | |
} | |
# Create PSObject with module name, scope, and installed location | |
$moduleObject = [PSCustomObject]@{ | |
Name = $moduleDetail.Name | |
Version = $version | |
Scope = $scope | |
InstalledLocation = $modulePath | |
} | |
# Add module object to array | |
$moduleInfo += $moduleObject | |
} | |
# Output the array of module objects | |
$moduleInfo | Sort-Object Name, Scope | |
} else { | |
Write-Host "No modules are installed." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment