forked from brianary/scripts
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathGet-ModuleScope.ps1
More file actions
54 lines (46 loc) · 1.52 KB
/
Get-ModuleScope.ps1
File metadata and controls
54 lines (46 loc) · 1.52 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<#
.SYNOPSIS
Returns the scope of an installed module.
.FUNCTIONALITY
PowerShell Modules
.INPUTS
System.Object with a "Name" or "ModuleName" property containing a module name.
.OUTPUTS
System.Management.Automation.PSObject with the following properties:
* ModuleName: The name of the module.
* Scope: The value "CurrentUser" if the module is found within $HOME\Documents\PowerShell\Modules, "AllUsers" if found anywhere else.
.EXAMPLE
Get-ModuleScope.ps1 Detextive
ModuleName Scope
---------- -----
Detextive CurrentUser
.EXAMPLE
Get-ModuleScope.ps1 Pester
ModuleName Scope
---------- -----
Pester CurrentUser
Pester AllUsers
#>
#Requires -Version 7
[CmdletBinding()][OutputType([string])] Param(
# Specifies names or name patterns of modules that this cmdlet gets. Wildcard characters are permitted.
[Parameter(Position=0,ValueFromPipelineByPropertyName=$true)][Alias('ModuleName')][string] $Name = '*'
)
Begin
{
$UserRoot = Join-Path $HOME Documents PowerShell Modules
}
Process
{
foreach($moduleName in Get-Module $Name -ListAvailable |Select-Object -ExpandProperty Name -Unique)
{
Get-Module $moduleName -ListAvailable |
Select-Object -ExpandProperty ModuleBase |
Split-Path |
Split-Path |
Select-Object -Unique |
ForEach-Object {$_ -eq $UserRoot ? 'CurrentUser' : 'AllUsers'} |
Select-Object -Unique |
ForEach-Object {[pscustomobject]@{ModuleName=$moduleName;Scope=$_}}
}
}