Skip to content

Instantly share code, notes, and snippets.

@futuremotiondev
Last active August 11, 2025 18:46
Show Gist options
  • Save futuremotiondev/64bdfcdee8de6a4c3e904efbecd63590 to your computer and use it in GitHub Desktop.
Save futuremotiondev/64bdfcdee8de6a4c3e904efbecd63590 to your computer and use it in GitHub Desktop.
Need help with proper Path and LiteralPath resolution
using namespace System.Collections.Generic
function Convert-ExampleFunction {
[CmdletBinding(DefaultParameterSetName="Path")]
param (
[Parameter(
Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName,
ParameterSetName = "Path",
HelpMessage="Path to one or more locations."
)]
[SupportsWildcards()]
[ValidateNotNullOrEmpty()]
[String[]] $Path,
[Parameter(
Mandatory,
Position = 0,
ValueFromPipelineByPropertyName,
ParameterSetName = "LiteralPath",
HelpMessage="Literal path to one or more locations."
)]
[ValidateScript({$_ -notmatch '[\?\*]'},
ErrorMessage = "Wildcard characters *, ? are not acceptable with -LiteralPath")]
[Alias('PSPath')]
[ValidateNotNullOrEmpty()]
[String[]] $LiteralPath
)
begin {
$fileTargets = [List[Object]]::new()
}
process {
# THIS IS WHERE I NEED HELP #################################################
# Do I use `Get-Item` or `Get-ChildItem`?
# Resolve either -Path or -LiteralPath
$resolved = if ($PSBoundParameters['Path']) {
Get-Item -Path $Path -Force
} elseif($PSBoundParameters['LiteralPath']) {
Get-Item -LiteralPath $LiteralPath -Force
}
# Perform desired filtering for what gets added to the $fileTargets list.
$resolved | % {
$item = $_
# Code goes here
$fileTargets.Add($item)
}
}
end {
# Perform final actions on $fileTargets
$svgTargets | % {
$curFile = $_
# Do stuff here
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment