internal/Resolve-AssemblyFilePath.ps1
#List of common locations for assemblies [System.Collections.ArrayList] $script:commonAssemblyFilePaths = @("$PSScriptRoot\..\assemblies","C:\Program Files (x86)\Microsoft SQL Server") <# .SYNOPSIS Attempts to resolve the the assembly file name specified to a fully qualified path. .DESCRIPTION Looks through the commonAssemblyFilePaths for files matching the specified file name. .PARAMETER AssemblyFileName Assembly file name. Ex. "Microsoft.Test.dll" .EXAMPLE Resolve-AssemblyFilePath -AssemblyFileName ".\test.dll" .OUTPUTS $null if no file found, otherwise the fully qualitifed path to the file. #> function Resolve-AssemblyFilePath{ [CmdletBinding()] param( [string] $AssemblyFileName ) foreach($assemblyFilePath in $script:commonAssemblyFilePaths){ $files = Get-ChildItem -Path $assemblyFilePath -Filter $AssemblyFileName -Recurse if(($files -ne $null) -and ($files.Length -gt 0)){ Write-Verbose "Found $($files.Length) files under $assemblyFilePath for $AssemblyFileName" #Return first match - may need to make a better strategy return $files[0].FullName } } return $null } <# .SYNOPSIS Adds to the common search paths used when attempting to resolve an assembly file location. .DESCRIPTION Adds a path to the list of paths to search. .EXAMPLE Add-CommonPath -Path "C:\Windows" #> function Add-CommonPath{ [CmdletBinding()] param( [string] $Path ) $script:commonAssemblyFilePaths.Add($Path) } <# .SYNOPSIS Clears the common search paths. .DESCRIPTION Clears the search path variable. .EXAMPLE Clear-CommonPath #> function Clear-CommonPath{ $script:commonAssemblyFilePaths = @() } |