App-V powershell backup script

08 Mar 2011 by Ryan Ververs-Bijkerk

Category:

    App-V

App-V powershell backup script

Table of Content

Some applications don't save the settings in the %appdata% directory. This can be a challenge when the application is virtualized. I have an application that save the settings in the installation directory. After repairing the application I lost my personal settings. This is not acceptable so I created a powershell script to backup the application settings. The script creates maximum 5 zip files and add the application settings based on the extension, this can be specific files too. The name of the zip file gets a date and time stamp. When the maximum is reached the oldest file that is created (not edit) is deleted. When the application is closed the script runs so the last settings will be saved. This way there is always a recent backup to restore. The script has two functions, one for creating the zip file and the second for adding content to the zip file. After the functions the total amount of zip files will be counted and sorted by creation date, this way the oldest zip file can be deleted. The lines highlighted in red can be edited to your application and backup location.

# Zip Functions function Add-Zip { param([string]$zipfilename) if(-not (test-path($zipfilename))) { set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) (dir$zipfilename).IsReadOnly = $false } $shellApplication = new-object -com shell.application $zipPackage = $shellApplication.NameSpace($zipfilename) foreach($file in $input) { $zipPackage.CopyHere($file.FullName) Start-sleep -milliseconds 500 } } function New-Zip { param([string]$zipfilename) set-content$zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) (dir$zipfilename).IsReadOnly = $false } # Zip Functions Closed # $Backup is the backup location include "\" $Backup = "D:\Data\Backup\App\" $Total = $(Get-ChildItem "$Backup").count While ($Total -gt 5) { $Files = Get-ChildItem "$Backup*.zip" | sort-Object-Property CreationTime Remove-Item $Files[0] $Total = $(Get-ChildItem "$Backup").count } $time = get-date-format dd-MM-yyyy.hh.mm $name = "D:\Data\Backup\App\Backup_" + $time +".zip" $content = dir "Q:\APP.001\APP\data\*.extension" new-zip $name dir$content -Recurse | add-Zip $name

To run the powershell script edit the OSD file and add the following lines:

<SCRIPT TIMING="POST" EVENT="SHUTDOWN" WAIT="TRUE" PROTECT="TRUE"> <SCRIPTBODY>Powershell.exe "D:\Data\Backup\App\Backup.ps1" </SCRIPTBODY> </SCRIPT>

For restoring I don't have a script yet. The way I do it is to open the explorer with the ACDC tool and copy the settings into the application bubble. Click here to download the ACDC tool (the download is only available after registration). If you have a question or suggestion, please leave a comment.

Tags:
    microsoft
    app-v
    powershell
    scripting
Ryan Ververs-Bijkerk
Written by Ryan Ververs-Bijkerk

Ryan is a self-employed technologist at GO-INIT who specializes in the EUC and code area. He primarily focuses on the user experience in centralized desktop environments.

Search

    Follow me

    Community