0

I have a SQL script that contains statements such as the following:

CREATE GROUP $MyGroup;
CREATE USER $MyUser;

Is there a way using Powershell that I can echo out the file contents with those variables replaced with their current values as set previously?

So if I had previously issued:

$MyGroup = 'group';
$MyUser = 'user';

the resultant string, after reading the file contents and substituting the variables, would be:

CREATE GROUP group;
CREATE USER user;

1 Answer 1

3

Yes, through the $ExecutionContext you can access the ExpandString function:

$fileContents = Get-Content myfile.sql
$ExecutionContext.InvokeCommand.ExpandString($fileContents)
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.