Join-String dependency fix + Get-Path cleanup

If Join-String is missing, the 'string' module, if not existing will be
installed and then imported.
Get-Path produced an error when used with wildcard, fixed it with string
substituation.
Get-Path would output wildcard string when expansion didn't match, now
output will be blank.
This commit is contained in:
Gal Szkolnik 2021-03-06 18:10:28 -05:00
parent 4da3726760
commit b5b5702b17
2 changed files with 15 additions and 1 deletions

View File

@ -27,17 +27,19 @@ process {
}
}
$p = $p -replace '#C-','#C-#' -replace '\*','#C-A#' -replace '\?','#C-Q#'
if([System.IO.Path]::IsPathRooted($p)){
$p = [System.IO.Path]::GetFullPath($p)
}else{
$p = [System.IO.Path]::GetFullPath((Join-Path $PWD $p))
}
$p = $p -replace '#C-A#','*' -replace '#C-Q#','?' -replace '#C-#','#C-'
if( $Expand ) {
$p = $p | ForEach-Object {
if( Test-Path $p ) {
$p | Get-Item -Force | Select-Object -ExpandProperty FullName
} else {
} elseif( -not $Expand ) {
$p
}
}

View File

@ -0,0 +1,12 @@
if( -not (Get-Command Join-String -ErrorAction SilentlyContinue) ) {
if( -not (Get-Module -ListAvailable -Name "string") ) {
Write-Warning 'Join-String Command is missing, attempting to install stirng module'
$local:moduleScope = "CurrentUser"
if( Test-IsAdmin ) { $moduleScope = "AllUsers" }
Install-Module -Name "string" -Scope $moduleScope -AllowClobber -ErrorAction SilentlyContinue
}
if( -not (Get-Module -ListAvailable -Name "string") ) {
Write-Error "Failed to locate/install the module 'string'"
}
Import-Module -Name "string" -Cmdlet "Join-String"
}