title: How to keep firefox bookmarks with powershell?
body: <p>like in <a href="https://stackoverflow.com/questions/71798462/what-is-the-difference-between-opening-application-by-cmd-ps-or-by-click">What is the difference between opening application by cmd/ps or by click?</a> already discussed, I have the problem, that firefox does not use my bookmarks, that I copied with powershell, as long as I open/close firefox within a script.</p>
  <p>The only chance I have is: open/close firefox manually and then overwrite bookmarks/passwords with powershell.</p>
  <p>Also I created the profile with arguments, but as soon as firefox will be opened, firefox is creating a new profile on its own. Obviously it makes a difference, whether I open firefox by click or ps/cmd.</p>
  <p>Does anybody has an idea, how to tell firefox which profile it shall use when the user opens firefox?</p>
  <p>Here my code:</p>
  <pre><code># Full path of the file
  $appdata = $env:APPDATA
  $folder = &quot;$appdata\Custom&quot;
  $checkfile = &quot;$folder\firstRunRestore&quot;
  
  #If the file does not exist, create it and execute statement.
  if (-not(Test-Path -Path $checkfile -PathType Leaf)) {
       try {
          $null = New-Item -ItemType File -Path $checkfile -Force -ErrorAction Stop
          
          #Create Firefox profile
          $p = New-Object System.Diagnostics.Process
          $p.StartInfo.UseShellExecute = $true;
          $p.StartInfo.WorkingDirectory = &quot;C:\Program Files\Mozilla Firefox&quot;;
          $p.StartInfo.Filename = &quot;firefox.exe&quot;;
          $p.StartInfo.Arguments = &quot;-CreateProfile $env:USERNAME&quot;;
          $null = $p.Start()
  
          Start-Sleep -s 10
          Stop-Process -Name &quot;Firefox&quot;
  
          # Wait to close all processes
          Start-Sleep -s 7
          
          # Restore files to profile
          $firefox = &quot;$env:APPDATA\Mozilla\Firefox\Profiles&quot;
          $curProfile = Get-ChildItem -Path $firefox | Sort-Object LastAccessTime -Descending | Select-Object -First 1
          $curPath = &quot;$firefox\$curProfile&quot;
          $source = &quot;X:\Desktop\FF-Profile&quot;
  
  
          $keydb = &quot;key4.db&quot;
          $logins = &quot;logins.json&quot;
          $places = &quot;places.sqlite&quot;
          $favicons = &quot;favicons.sqlite&quot;
  
          Copy-Item -Path &quot;$source\$keydb&quot; -Destination &quot;$curPath&quot; -Force
          Copy-Item -Path &quot;$source\$logins&quot; -Destination &quot;$curPath&quot; -Force
          Copy-Item -Path &quot;$source\$places&quot; -Destination &quot;$curPath&quot; -Force
          Copy-Item -Path &quot;$source\$favicons&quot; -Destination &quot;$curPath&quot; -Force
  
          Remove-Item $source -Force -Recurse
       }
       catch {
           throw $_.Exception.Message
       }
   }
  </code></pre>