13

I would like in my script to use wildcard in variable like this :

$TARGET = "\\MACHINE1\c$\ProgramData\Test\12.*\Data\"

The problem is $TARGET returns

\\MACHINE1\c$\ProgramData\Test\12.*\Data\

and not

\\MACHINE1\c$\ProgramData\Test\12.1.1.1\Data\

However

Test-Path "\\MACHINE1\c$\ProgramData\Test\12.*\Data\"

=> TRUE

Thanks for your help

2
  • 1
    So, what is the question? Commented Aug 3, 2015 at 11:30
  • The question is : How can I write in the variable $TARGET the correct path without the wildcard Commented Aug 3, 2015 at 11:32

2 Answers 2

17

The Best in this cases IMO is using Resolve-Path,

$TARGET = Resolve-Path "\\MACHINE1\c$\ProgramData\Test\12.*\Data\" | Select -ExpandProperty Path
Sign up to request clarification or add additional context in comments.

Comments

6

You should use Get-ChildItem to retrieve the real path:

$TARGET = "\\MACHINE1\c$\ProgramData\Test\12.*\Data\"
Get-ChildItem $Target


    Directory: \\MACHINE1\c$\ProgramData\Test\12.1.1.1

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        10-10-2014     12:48            data

2 Comments

Is it possible to save it in a variable ?
$TARGET = Get-ChildItem -Path "\\MACHINE1\c$\ProgramData\Test\12.*\Data\"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.