Sep 30 2017 09:25 PM
Hello,
I am new to power shell and i am trying to achive below. I have file test.txt with data as shown below.
i want the search for variable2 and update the value as below.
select * from table1 order by column
Can you please guide me on how to achive this?
cat test.txt
variable1=DB1
variable2=select * from table1;
Oct 01 2017 01:44 AM
Do you need to run it in powershell trough a txt file or can you run it in a script?
You could take a look at this article on how to query SQL from PowerShell:
http://irisclasson.com/2013/10/16/how-do-i-query-a-sql-server-db-using-powershell-and-how-do-i-filte...
Oct 09 2017 02:14 AM
How about this?
it will
Copy-Item .\test.txt .\test.tmp; Get-Content test.tmp|ForEach-Object {if($_ -match '^ *variable2 *=') { "variable2=select * from table1 order by column"} else {$_}} | Out-File .\test.txt; Remove-Item .\test.tmp