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:
parent
4da3726760
commit
b5b5702b17
|
@ -27,17 +27,19 @@ process {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$p = $p -replace '#C-','#C-#' -replace '\*','#C-A#' -replace '\?','#C-Q#'
|
||||||
if([System.IO.Path]::IsPathRooted($p)){
|
if([System.IO.Path]::IsPathRooted($p)){
|
||||||
$p = [System.IO.Path]::GetFullPath($p)
|
$p = [System.IO.Path]::GetFullPath($p)
|
||||||
}else{
|
}else{
|
||||||
$p = [System.IO.Path]::GetFullPath((Join-Path $PWD $p))
|
$p = [System.IO.Path]::GetFullPath((Join-Path $PWD $p))
|
||||||
}
|
}
|
||||||
|
$p = $p -replace '#C-A#','*' -replace '#C-Q#','?' -replace '#C-#','#C-'
|
||||||
|
|
||||||
if( $Expand ) {
|
if( $Expand ) {
|
||||||
$p = $p | ForEach-Object {
|
$p = $p | ForEach-Object {
|
||||||
if( Test-Path $p ) {
|
if( Test-Path $p ) {
|
||||||
$p | Get-Item -Force | Select-Object -ExpandProperty FullName
|
$p | Get-Item -Force | Select-Object -ExpandProperty FullName
|
||||||
} else {
|
} elseif( -not $Expand ) {
|
||||||
$p
|
$p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
|
}
|
Loading…
Reference in New Issue