This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathGet-InstalledScriptFilePath.ps1
More file actions
42 lines (36 loc) · 1.72 KB
/
Get-InstalledScriptFilePath.ps1
File metadata and controls
42 lines (36 loc) · 1.72 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
function Get-InstalledScriptFilePath
{
[CmdletBinding(PositionalBinding=$false)]
Param
(
[Parameter()]
[string]
$Name
)
$installedScriptFilePaths = @()
$scriptFilePaths = Get-AvailableScriptFilePath @PSBoundParameters
foreach ($scriptFilePath in $scriptFilePaths)
{
$scriptInfo = Test-ScriptInstalled -Name ([System.IO.Path]::GetFileNameWithoutExtension($scriptFilePath))
if($scriptInfo)
{
$installedScriptInfoFilePath = $null
$installedScriptInfoFileName = "$($scriptInfo.Name)_$script:InstalledScriptInfoFileName"
if($scriptInfo.Path.StartsWith($script:ProgramFilesScriptsPath, [System.StringComparison]::OrdinalIgnoreCase))
{
$installedScriptInfoFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:ProgramFilesInstalledScriptInfosPath `
-ChildPath $installedScriptInfoFileName
}
elseif($scriptInfo.Path.StartsWith($script:MyDocumentsScriptsPath, [System.StringComparison]::OrdinalIgnoreCase))
{
$installedScriptInfoFilePath = Microsoft.PowerShell.Management\Join-Path -Path $script:MyDocumentsInstalledScriptInfosPath `
-ChildPath $installedScriptInfoFileName
}
if($installedScriptInfoFilePath -and (Microsoft.PowerShell.Management\Test-Path -Path $installedScriptInfoFilePath -PathType Leaf))
{
$installedScriptFilePaths += $scriptInfo.Path
}
}
}
return $installedScriptFilePaths
}