Backup Firefox profile from logged on user

Dear community,

im bothering myself at the moment with a silly little problem regarding backup a folder when using pdq deploy enterprise 12

Normally i would assume, that when updating firefox browser using pdq deploy the profile folder wont be affected nor beeing destroyed by any reason. Yet for backup issue this backup is recommended from a department before browser update is done.

´The main goal should be, that the firefox profile folder which is found usualy in this path -> %userprofile%\AppData\Roaming\Mozilla\Profiles\ (assuming its for Windows 7) from the logged on user to a local backup folder like c:\mozilla

Now i struggle with matching the deploy script for the logged on user to make sure i only grab the Mozilla profile folder of the logged on user.

Did someone else might had the same or similar issue to handle and could give me an idea how to solve this?

I do am aware that the logged on user condition might be part of the solution :)


Kind regards







Date Votes
  • I just wrote this and tested it on Windows 8.1, the path appears to be the same for the profile between Win 7 and 8.1, so should work as-is but the path might need a little tweaking.


    Insert a powershell step and paste this code into the step, or save this code into a .ps1 file and Insert a Powershell Script into the Powershell step, whichever you want to do.

    In the screenshot above I put the step right above the Install step on the imported package as an example, but really you could put it anywhere before the install step, in fact it might be best to grab that backup first before the package does anything else to the remote system. You can clearly see in the screenshot the big white window to paste code into, or the link below if you want to save this as a .ps1 file and insert it that way. Again, should make no difference which way you do it, I'll leave it up to you.

    Here's the code: 

    #Get logged on user, remove the domain portion so it's just the username
    $loggedonuser = (Get-WmiObject -Class win32_ComputerSystem | Select Username).Username.Split('\')[1]

    #Build backup source from user variable
    $FFProfileSource = "C:\Users\$loggedonuser\AppData\Roaming\Mozilla\Firefox\Profiles"

    #Create backup destination on target

    $FFProfilebackup = New-Item -Path C:\Mozilla -Name FFProfileBackup -ItemType Directory

    #Copy the profile to backup location

    Copy-Item -Path $FFProfileSource -Recurse -Destination $FFProfilebackup -Force


    If you are using Auto-Deployments, you can insert a Pre-Step and do a Powershell step there, so this will work no matter which way you need to use it.

  • Gah, Stephen beat me to it! I'll still post mine though, because I added oldest backup deletion :)

    Write-Output "Current user: $env:USERNAME"

    $Firefox_Profile = "$env:SYSTEMDRIVE\Users\$env:USERNAME\AppData\Roaming\Mozilla\Firefox\Profiles"
    if ( Test-Path "$Firefox_Profile" ) {

    $Timestamp = Get-Date -Format "yyyy-MM-dd"
    $Backup_Destination = "$env:SYSTEMDRIVE\Firefox_Backup\$env:USERNAME"
    Copy-Item -Recurse "$Firefox_Profile" "$Backup_Destination\$Timestamp"

    $All_Backups = Get-ChildItem "$Backup_Destination" | Sort-Object Name
    if ( $All_Backups.Length -gt 10 ) {

    Write-Output "Deleting oldest backup $($All_Backups[0].FullName)"
    Remove-Item -Recurse -Force "$($All_Backups[0].FullName)"


    } else {

    Write-Output "This user does not have a Firefox profile at $Firefox_Profile"

  • You know. I was going to add in some sort of deletion mechanism, but hesitated cause I couldn't decide how I wanted to do it. I like your approach very much. also, smart use of the $env:SYSTEMDRIVE. I always just assume people use C:\ haha.


    Curiousity question: Why the use of write-output in your script? Does you wrapper capture that for output.log?

  • I have been trying to use Write-Output in Deploy scripts lately because Deploy throws a warning if you use Write-Host. It doesn't actually matter, but I prefer if the code I give people doesn't show that warning :).

    Also, yes my output shows up in Output.log.

  • Write-Host is the devil. I never ever use it except in cases where I'm testing, but it gets either commented out, or changed to write-output in the final version of code. You can actually DO STUFF with write-output, whereas Write-Host is basically echo and worthless in production haha.


    Good to know that Write-Output is put in output.log. That's actually extremely useful to know. I'll start being more verbose in things I'm both in my own stuff, and in the help I provide here! Thanks, Colby.

  • Thanks a lot for both comments, i appreciate your efford a lot :)
    Ill test it out and im pretty sure it helps me to solve my stuff in this issue!

    Kind regards



Please sign in to leave a comment.

Didn't find what you were looking for?

New post