problem with writing $ variables to text in powershell

Viewed 38

I want to write a script which creates a php file. For that, I create a text file and I add the code from the script :

  New-Item "test.php" -ItemType File -Value 
"<?php 
      require(""iExec2.php"");
      $SDescri = new Descri();"

The text file is created but it does not add the variables with a $ : enter image description here

I tried '$SDescri', "$SDescri", $'SDescri', '"' $SDescri '"', ... in short lots of combinations to add the variable in the text file but none of them work.

Is that possible to do that in powershell or I need to find another way to create a php file with the variables ?

1 Answers

You've got a couple of options

"<?php 
require(""iExec2.php"");
`$SDescri = new Descri();"

'<?php 
require("iExec2.php");
$SDescri = new Descri();'

@"
<?php 
require("iExec2.php");
$SDescri = new Descri();
"@
Related