It's tough to think of a good solution for that. Essentially, you want a parameter that treats some special characters specially, but treats others as literals - sometimes. It almost would another param, right? One where you pass it an array of characters you do/do not want treated as wildcards or whatever?
get-whatever -path "string" -noGlop @("[","]")
Right?
--
Don Jones
Windows PowerShell MVP
Founder:
www.ScriptingAnswers.com
Co-Author: "Windows PowerShell: TFM"
"Keith Hill [MVP]" <r_keith_hill@no.spam.thank.u.hotmail.com> wrote in message news:uGNDu10kHHA.4904@TK2MSFTNGP05.phx.gbl...
"IJuan" <IJuan@discussions.microsoft.com> wrote in message news:ABCB1E33-5E54-4289-8730-BC854A2EDE3D@microsoft.com...
> Copy-Item seems to treat the destination as a literalpath by default. This
> does work:
>
> copy-item 'foo.txt' 'c:\temp\[somedir]'
> copy-item -literalpath 'c:\[somedir]\foo.txt' 'c:\temp[somedir]'
That's fine but elsewhere I need to have part of that path (the part with []) globbed so I have to define the base part of the path like so:
$InstallDropDir = "$ProductDir\``[productspecific``]"
This allows me to do this in one function:
$LatestMsi = get-childitem "$InstallDropDir\*.msi" | sort LastWriteTime | select -last 1
However in another function I need to do a copy based on $InstallDropDir:
copy-item $foo $InstallDropDir
Doh - that doesn't work, so I have to do a hack like this:
$dst = $InstallDropDir.Replace('`','')
copy-item $foo $dst
These little fits of insanity add to a feeling of frustration with PowerShell - sometimes. Most of the time of course, it is all wine and roses. :-)
--
Keith