0

i have a requirement in powershell if filename contains abc then set $tablename to abc_stg if filename contains pqr set $tablename to pqr_stg. Can anyone help.

switch ($file_name) {
    abc {"dbo.abc_stg"}
    pqr {"dbo.pqr_stg"}

}

1 Answer 1

1

See this page: Using Wildcards with the Switch Statement

In your case:

$tablename = switch -wildcard ($file_name)
    {
        "*abc*" { "dbo.abc_stg" }
        "*pqr*" { "dbo.pqr_stg" }
        default { "No match" }
    }
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.