Public/Get-PSDependType.ps1
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
Function Get-PSDependType { <# .SYNOPSIS Get dependency types and related information .DESCRIPTION Get dependency types and related information Checks PSDependMap.psd1 for dependency types, verifies dependency scripts exist, gets help content for dependency scripts, returns various info on each dependency type .PARAMETER Path Path to PSDependMap.psd1 defining dependency types Defaults to PSDependMap.psd1 in the module root .PARAMETER DependencyType Optionally limited to this DependencyType Accepts wildcards .PARAMETER ShowHelp Show help content for specified dependency types .PARAMETER SkipHelp Skip retreieving help. Mainly for internl use when it is not required .EXAMPLE Get-PSDependType -DependencyType PSGalleryModule -ShowHelp Show help for the PSGalleryModule dependency type. .EXAMPLE Get-PSDependType # List dependency types defined in PSDependMap.psd1 in the root of your PSDepend module folder .EXAMPLE Get-PSDependType -Path \\Path\To\Central.DependencyMap.psd1 # List dependency types defined in a centralized dependency map .LINK about_PSDepend .LINK about_PSDepend_Definitions .LINK Get-Dependency .LINK Get-PSDependScript .LINK Install-Dependency .LINK Invoke-PSDepend .LINK https://github.com/RamblingCookieMonster/PSDepend #> [cmdletbinding()] param( [string]$DependencyType = '*', [validatescript({Test-Path $_ -PathType Leaf -ErrorAction Stop})] [string]$Path = $(Join-Path $ModuleRoot PSDependMap.psd1), [switch]$ShowHelp, [switch]$SkipHelp ) # Read the file $Base = Split-Path $Path -Parent $File = Split-Path $Path -Leaf $DependencyDefinitions = Import-LocalizedData -BaseDirectory $Base -FileName $File $KeysToQuery = $DependencyDefinitions.Keys | Where-Object {$_ -like $DependencyType} | Sort-Object foreach($Type in $KeysToQuery) { #Determine the path to this script. Skip task dependencies... $Script = $DependencyDefinitions.$Type.Script if($Script -ne '.') { if(Test-Path $Script) { $ScriptPath = $Script } else { # account for missing ps1 $ScriptPath = Join-Path $ModuleRoot "PSDependScripts\$($Script -replace ".ps1$").ps1" } If (-not $SkipHelp) { Try { $ScriptHelp = Get-Help $ScriptPath -Full -ErrorAction Stop } Catch { $ScriptHelp = "Error retrieving help: $_" } } } if($ShowHelp) { $ScriptHelp } else { $Support = @($DependencyDefinitions.$Type.Supports) [pscustomobject]@{ DependencyType = $Type Supports = $Support Supported = Test-PlatformSupport -Type $Type -Support $Support Description = $DependencyDefinitions.$Type.Description DependencyScript = $ScriptPath HelpContent = $ScriptHelp } } } } |