Backup Firefox profile from logged on user

Comments

6 comments

  • Stephen Valdinger

    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.


    0
    Comment actions Permalink
  • Colby Bouma

    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"

    }
    0
    Comment actions Permalink
  • Stephen Valdinger

    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?

    0
    Comment actions Permalink
  • Colby Bouma

    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.

    0
    Comment actions Permalink
  • Stephen Valdinger

    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.

    0
    Comment actions Permalink
  • Markus Hochkoeppeler

    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

    Markus

    0
    Comment actions Permalink

Please sign in to leave a comment.