---rOOts---
Senior Member
Absolut klasse!
Ich habe diesen Code verwendet!
Und ihn einmal als PowerShell-Skript ausgeführt und ein zweites Mal als EXE. Klasse!
Und von wegen Performanceverlust, das ganze geht schneller als mit
und auch schneller als mit
Eine letzte Sache aber hätte ich da noch!
Ich will ja nicht immer auch das Programmverzeichnis mit sichern,
also muss da eine Abfrage rein.
Natürlich muss das dann zwischen die zwei Packbefehle.
Hier der aktuelle Stand:
Ich habe diesen Code verwendet!
Code:
$7z = ".\7z.exe"
&$7z a -mx5 -bso0 -bsp1 "$LogPfad\$profile.zip" "$env:appdata\Mozilla\Firefox\Profiles" | out-string -stream | Select-String -Pattern "\d+(?=%)" -AllMatches |
ForEach-Object { Write-Progress -Activity "Profilverzeichnis wird archiviert... " -PercentComplete ([int]$_.Matches.Value) -Status " "}
&$7z a -mx5 -bso0 -bsp1 "$LogPfad\$program.zip" "$env:ProgramFiles\Mozilla Firefox" | out-string -stream | Select-String -Pattern "\d+(?=%)" -AllMatches |
ForEach-Object { Write-Progress -Activity "Programmverzeichnis wird archiviert... " -PercentComplete ([int]$_.Matches.Value) -Status " "}
Und ihn einmal als PowerShell-Skript ausgeführt und ein zweites Mal als EXE. Klasse!
Und von wegen Performanceverlust, das ganze geht schneller als mit
Code:
Compress-Archive -Path "$env:appdata\Mozilla\Firefox\Profiles" -DestinationPath "$LogPfad\$profile.zip" -CompressionLevel Optimal
Code:
compress-7zip -path "$env:appdata\Mozilla\Firefox\Profiles" -CompressionLevel Normal -ArchiveFileName "$LogPfad\$profile.zip" -Format Zip
Eine letzte Sache aber hätte ich da noch!
Ich will ja nicht immer auch das Programmverzeichnis mit sichern,
also muss da eine Abfrage rein.
Code:
if (? (?)) {
$wshshell = new-object -comobject wscript.shell
$Answer = $wshshell.popup("Moechten Sie das Programmverzeichnis auch sichern?",0,"Firefox4backup",4)
switch ($Answer) {
# 6 entspricht "Ja"
6 {
Remove-Item -Path $LogPfad -Force -Recurse
Write-Host "Das Programmverzeichnis wurde auch gesichert."
}
# 7 entspricht "Nein"
7 {
Write-Host "Das Programmverzeichnis wurde nicht gesichert."
!!Hier muss die Sprunganweisung zu "if (!(Test-Path ("$LogPfad\Sicherung am $date.txt"))) { "hin !!!
}
}
}
Hier der aktuelle Stand:
Code:
$ProcessName = "Firefox"
if (Get-Process $ProcessName -ErrorAction SilentlyContinue) {
$wshshell = New-Object -ComObject WScript.Shell
$Frage = $wshshell.Popup("Soll $ProcessName beendet werden?", 0, "$ProcessName ist noch aktiv.", 4)
if ($Frage -eq 6) {
Get-Process $ProcessName | Stop-Process
}
else {
Exit
}
}
else {
Write-Host "$ProcessName ist nicht aktiv."
}
$date = Get-Date -Format "yyyy.MM.dd - HH.mm.ss"
$datum = Get-Date -Format "yyyy.MM.dd"
Add-Type -A System.Windows.Forms
$SelectDir = [Windows.Forms.FolderBrowserDialog] @{
RootFolder = "MyComputer"
Description = "Waehlen Sie das Laufwerk fuer die Sicherung aus:"
}
if ($SelectDir.ShowDialog() -ne "OK") {return}
$LogPfad = "$($SelectDir.SelectedPath)\BackupFirefox\$datum"
if (Test-Path ($LogPfad)) {
$wshshell = new-object -comobject wscript.shell
$Answer = $wshshell.popup("Moechten Sie das Verzeichnis und alle darin enthaltenen Dateien wirklich loeschen?",0,"Das Verzeichnis $LogPfad existiert bereits.",4)
switch ($Answer) {
# 6 entspricht "Ja"
6 {
Remove-Item -Path $LogPfad -Force -Recurse
Write-Host "Das Verzeichnis wurde gelöscht."
}
# 7 entspricht "Nein"
7 {
Write-Host "Das Verzeichnis wird nicht gelöscht. Das Skript wird beendet."
Exit
}
}
}
if(!(Test-Path ($LogPfad))) {
New-Item -Path $LogPfad -ItemType Directory
}
$profile = "Profilverzeichnis"
$program = "Programmverzeichnis"
$7z = ".\7z.exe"
&$7z a -mx5 -bso0 -bsp1 "$LogPfad\$profile.zip" "$env:appdata\Mozilla\Firefox\Profiles" | out-string -stream | Select-String -Pattern "\d+(?=%)" -AllMatches |
ForEach-Object { Write-Progress -Activity "Profilverzeichnis wird archiviert... " -PercentComplete ([int]$_.Matches.Value) -Status " "}
&$7z a -mx5 -bso0 -bsp1 "$LogPfad\$program.zip" "$env:ProgramFiles\Mozilla Firefox" | out-string -stream | Select-String -Pattern "\d+(?=%)" -AllMatches |
ForEach-Object { Write-Progress -Activity "Programmverzeichnis wird archiviert... " -PercentComplete ([int]$_.Matches.Value) -Status " "}
if (!(Test-Path ("$LogPfad\Sicherung am $date.txt"))) {
$FF_Version = gp 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'| ? DisplayName -like "*firefox*"|select -Expand DisplayVersion
$Logfile = (New-Item -Path "$LogPfad\Sicherung am $date.txt" -ItemType File -Force).FullName
Add-Content $Logfile ("Letzte Sicherung von Firefox am $(get-date -Format "dddd, dd. MMMM yyyy, HH:mm:ss") Uhr`n")
Add-Content $Logfile ("Die gesicherte Firefox-Version ist: $FF_Version")
Add-Content $Logfile "`n`n"
}
$wshshell = new-object -comobject wscript.shell
$Answer = $wshshell.popup("Sicherung abgeschlossen",0,"Firesave",0)