0

I am trying to modify several values of a PowerShell script template prior to execution. The approach I took was to use the Get-Content command to read the template file, then to use the replace operand to replace the content with a content of my choosing, and then the Set-Content command to update the file, then execute the script. However, according to the error messages that I encounter, it seems that the modified file is not running, but the template one. The thing I find hard to understand is why, as I use the Get-Content once again and print the result prior to execution, where I witness that the file did change.

I use simple PowerShell scripting with no threads or so ever, the script is being executed on an Azure VM via the Run-Command feature. I wonder why it happens. Can anyone please explain?

AdyM
  • 13
  • 4
  • I wonder if its caching scripts per-session. Does it still appear to run the old version of the script if you do it via a new powershell session? i.e Start-Process pwsh -ArgumentList "pathtoyourscript" -Verb RunAs – diopside Nov 07 '21 at 21:04
  • 5
    please add your actual code - reduced to the minimum that reproduces the error - to your Question & wrap it in code format markers. – Lee_Dailey Nov 07 '21 at 23:25
  • Instead of templating, you may consider using parameters. This way you don't need to modify the script everytime you run it. [How to use parameters in PowerShell](https://www.red-gate.com/simple-talk/sysadmin/powershell/how-to-use-parameters-in-powershell/) – zett42 Nov 08 '21 at 12:16
  • I cant I download this script from git and then need to change the endpoint – AdyM Nov 14 '21 at 07:27

0 Answers0