title: How to change properties of already existing OLEDB connection in excel using powershell?
body: <p>I have a excel (connection.xlsx) which imports data from a Old.csv using OLEDB connection.</p>
  <p>Connection String looks like below in excel:
  Connection String: Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Old;Extended Properties=&quot;&quot;
  Connection Text: SELECT * FROM [Old]</p>
  <p>I want to change this connection string programmatically using powershell to load data from other excel file New.csv</p>
  <p>Connection String: Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=New;Extended Properties=&quot;&quot;
  Connection Text: SELECT * FROM [New]</p>
  <p>I am trying like this:</p>
  <pre><code>clear
  # Powershell Code
  $xlsx = &quot;C:\Users\umashankar.jedgule\Desktop\Terracon\BnMPOC\Connection.xlsx&quot;
  $Excel = New-Object -comobject Excel.Application
  $ExcelWorkbook = $Excel.workbooks.open($xlsx) 
  $conn = $ExcelWorkbook.Connections
  echo $conn
  $i=1 
  foreach($con in $conn)
  {
  $con.OLEDBConnection.Connection = 'OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=New;Extended Properties=&quot;&quot;'
  $con.OLEDBConnection.CommandText = 'SELECT * FROM [New]'
  $flag=$con.OLEDBConnection.BackgroundQuery
  $con.OLEDBConnection.BackgroundQuery=$false
  $con.refresh()
  $con.OLEDBConnection.BackgroundQuery=$flag
  echo $con.OLEDBConnection.Connection
  echo $con.OLEDBConnection.CommandTex
  echo $test
  $i = $i + 1
   }
  $ExcelWorkbook.refreshall()
  $ExcelWorkbook.Save()
  $ExcelWorkbook.Close()
  $ExcelWorkbook.Quit()
  </code></pre>
  <p>But prompt is not moving ahead. I am not sure whether above code is correct or not. Please suggest.</p>
  <p><a href="https://i.stack.imgur.com/8tBS3.png" rel="nofollow noreferrer">enter image description here</a></p>