Private/Resolve-FullPath.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
function Resolve-FullPath {
    [CmdletBinding()]
    param (
        # Path to be resolved.
        # Can be realtive or absolute.
        # Resolves PSDrives
        [Parameter( Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName )]
        [ValidateNotNullOrEmpty()]
        [ValidateScript(
            {
                if (-not (Test-Path $_ -PathType Leaf)) {
                    $errorItem = [System.Management.Automation.ErrorRecord]::new(
                        ([System.ArgumentException]"File not found"),
                        'ParameterValue.FileNotFound',
                        [System.Management.Automation.ErrorCategory]::ObjectNotFound,
                        $_
                    )
                    $errorItem.ErrorDetails = "No file could be found with the provided path '$_'."
                    $PSCmdlet.ThrowTerminatingError($errorItem)
                }
                else {
                    return $true
                }
            }
        )]
        [Alias( 'FullName', 'PSPath' )]
        [String]
        $Path
    )

    process {
        Write-Verbose "[$($MyInvocation.MyCommand.Name)] Resolving path $Path"
        $PSCmdlet.GetUnresolvedProviderPathFromPSPath($Path)
    }
}