Skip to content

Instantly share code, notes, and snippets.

@blakedrumm
Last active March 26, 2024 19:39
Show Gist options
  • Save blakedrumm/a902c31fd46a5a3c2385884a22392611 to your computer and use it in GitHub Desktop.
Save blakedrumm/a902c31fd46a5a3c2385884a22392611 to your computer and use it in GitHub Desktop.
This grabs the Name, Version, Scope, and InstalledLocation.
# Author: Blake Drumm (blakedrumm@microsoft.com)
# 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