0

There is one requirement where i need to pass a variable that is set in the powershell to the another variable

Please find the below example

    PS D:\temp\arun> $match1=get-date -format ddMMM
    PS D:\temp\arun> $match1
    19Jun

test.txt file has the below content

    19Jun1
    19Jun2
    19Jun3

    PS D:\temp\arun> $match2=select-string -simple 19Jun test.txt
    PS D:\temp\arun> $match2
    19Jun1
    19Jun2
    19Jun3

But when i am trying to pass the variable i am not getting the result.

    PS D:\temp\arun> $match2=select-string -simple $match1 test.txt
    PS D:\temp\arun> $match2

Could any one please help me in this?

3
  • Works for me as expected. Is there anything in your script that might interfere with $match1 or change its value? Commented Jun 19, 2013 at 10:03
  • What the output you are getting @ShayLevy I am not getting any output Commented Jun 19, 2013 at 10:09
  • @ShayLevy when i tried again it worked..sorry for the trouble. :) Happy now :) Commented Jun 19, 2013 at 10:11

1 Answer 1

1

Works fine here. Try specifying the paramters to make sure the right value is assigned to the right parameter.

$match2 = Select-String -SimpleMatch -Pattern $match1 -Path .\test.txt
Sign up to request clarification or add additional context in comments.

Comments

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.