title: Powershell: Openfile dialog and Set-Content Issue. Cannot access file. In use
body: <p>What I'm trying to do is utilize the openfile dialog, select an ini file and make line changes to it at the end of this script with set-content.  But I keep getting the error that Set-Content : The process cannot access the file, and that it's in use.  </p>
  
  <pre><code>$a = $env:userprofile
  Function Get-FileName($InitialDirectory)
  {
  Get-FileName -InitialDirectory "$a\AppData\Roaming\Milliman"
  }#end function Get-FileName
  
  [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
  $dialog = New-Object System.Windows.Forms.OpenFileDialog
  $dialog.DefaultExt = '.*'
  $dialog.Filter = 'All Files|*.*'
  $dialog.FilterIndex = 0
  $dialog.InitialDirectory = $InitialDirectory
  $dialog.Multiselect = $false
  $dialog.RestoreDirectory = $true
  $dialog.Title = "Select a file"
  $dialog.ValidateNames = $true
  $dialog.ShowHelp = $true
  $dialog.ShowDialog()
  $dialog.FileName
  
  
  ##Folder Dialog
  $dir = new-object -com Shell.Application
  $aldir = $dir.BrowseForFolder(0, "AL Dir", 0, "C:\Program Files\Milliman\")
  if ($aldir.Self.Path -ne "") {write-host "You selected " $aldir.Self.Path}
  
  
  ## Grid Integration Steps
  
  Copy-Item -path "\\ap102aric\alfaadmin$\Ver70andAbove\DataSynapse\*" -destination "C:\Program     Files\Common Files\Milliman\MG-ALFA Shared\DataSynapse" -Force
  
  Copy-Item -path "\\ap102aric\alfaadmin$\Ver70andAbove\JobOptions-RPRic\*"  -destination "C:\Program Files\Common Files\Milliman\MG-ALFA Shared\DataSynapse" -Force
  
  Copy-Item -path "\\ap102aric\alfaadmin$\Ver70andAbove\GSDLL\dsdrv.dll" -Destination $aldir.Self.Path -Force
  
  
  ## Set Environment Variable
  [Environment]::SetEnvironmentVariable("DSDRIVER_DIR","C:\Program Files\Common Files\Milliman\MG-ALFA Shared\DataSynapse\Config","Machine")
  
  ## Edit Config UI.ini to set SDP LOGON for Datasynapse
  #Write-Host $dialog.FileName
  Get-Content $dialog.FileName | ForEach-Object {
  $_ -replace 'SDPAvailable=*','SDPAvailable=DataSynapse'
     -replace 'SDPFolder=*','SDPFolder=C:\Program Files\Common Files\Milliman\MG-ALFA Shared\DataSynapse'
     -replace 'SDPLogon=*','SDPAvailable=Yes'
   } | Set-Content $dialog.FileName
  </code></pre>