Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| backuppersonnalfolder [2019/12/05 16:14] – [Script principal] nekan | backuppersonnalfolder [2021/03/05 16:12] (Version actuelle) – nekan | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| - | ~~CLOSETOC~~ | ||
| ====== Backup-PersonnalFolder - Sauvegarde de dossiers utilisateurs ====== | ====== Backup-PersonnalFolder - Sauvegarde de dossiers utilisateurs ====== | ||
| + | <label type=" | ||
| Il y a des utilisateurs qui prennent l' | Il y a des utilisateurs qui prennent l' | ||
| Ligne 429: | Ligne 429: | ||
| # Formatage du chemin du ShadowCopy | # Formatage du chemin du ShadowCopy | ||
| $CorrectPath = $ID.DeviceObject + " | $CorrectPath = $ID.DeviceObject + " | ||
| + | # Création du type d' | ||
| + | Try | ||
| + | { | ||
| + | $Null = [Win32.SymLink] | ||
| + | } | ||
| + | Catch | ||
| + | { | ||
| + | Add-Type @" | ||
| + | using System; | ||
| + | using System.Runtime.InteropServices; | ||
| + | | ||
| + | namespace Win32 | ||
| + | { | ||
| + | public class SymLink | ||
| + | { | ||
| + | [DllImport(" | ||
| + | public static extern bool CreateSymbolicLink(string lpSymlinkFileName, | ||
| + | } | ||
| + | } | ||
| + | "@ | ||
| + | } | ||
| + | | ||
| # Création du lien symbolique | # Création du lien symbolique | ||
| - | cmd /c mklink /d C: | + | [Win32.SymLink]:: |
| - | + | ||
| # Identifiants pour l' | # Identifiants pour l' | ||
| $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Pass | $Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $Pass | ||
| Ligne 455: | Ligne 477: | ||
| $FileToBackup | ForEach-Object { | $FileToBackup | ForEach-Object { | ||
| $FileFullName = $_.FullName | $FileFullName = $_.FullName | ||
| - | $PrintName = $FileFullName.Replace('ShadowCopy\', '' | + | $PrintName = $FileFullName.Replace("ShadowCopy\", '' |
| $TestFile = ($_.FullName).Replace($ScriptSource, | $TestFile = ($_.FullName).Replace($ScriptSource, | ||
| $TestFileType = (Get-Item -Path $TestFile).GetType().Name | $TestFileType = (Get-Item -Path $TestFile).GetType().Name | ||
| - | If ((Test-Path $TestFile) -and ($TestFileType -ne 'DirectoryInfo')) | + | If ((Test-Path $TestFile) -and ($TestFileType -ne "DirectoryInfo")) |
| { | { | ||
| $SourceFileDate = Get-Date -Date (Get-ItemProperty -Path $FileFullName).LastWriteTime | $SourceFileDate = Get-Date -Date (Get-ItemProperty -Path $FileFullName).LastWriteTime | ||
| Ligne 468: | Ligne 490: | ||
| { | { | ||
| Copy-Item -Path $FileFullName -Destination $TestFile | Copy-Item -Path $FileFullName -Destination $TestFile | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Catch | Catch | ||
| { | { | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Ligne 481: | Ligne 503: | ||
| { | { | ||
| $RecentFile = $TestFile.Replace(" | $RecentFile = $TestFile.Replace(" | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Ligne 487: | Ligne 509: | ||
| If ($SourceFileDate -eq $DestinationFileDate) | If ($SourceFileDate -eq $DestinationFileDate) | ||
| { | { | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Ligne 502: | Ligne 524: | ||
| { | { | ||
| Remove-Item -Path $FileFullName -Force -Recurse 2> $Null | Remove-Item -Path $FileFullName -Force -Recurse 2> $Null | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Catch | Catch | ||
| { | { | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Ligne 517: | Ligne 539: | ||
| $FileFullName = $_.FullName | $FileFullName = $_.FullName | ||
| $TestFile = ($_.FullName).Replace($ScriptSource, | $TestFile = ($_.FullName).Replace($ScriptSource, | ||
| - | $PrintName = $FileFullName.Replace('ShadowCopy\', '' | + | $PrintName = $FileFullName.Replace("ShadowCopy\", '' |
| If (-not (Test-Path $TestFile)) | If (-not (Test-Path $TestFile)) | ||
| { | { | ||
| Ligne 523: | Ligne 545: | ||
| { | { | ||
| Copy-Item -Path $FileFullName -Destination $TestFile | Copy-Item -Path $FileFullName -Destination $TestFile | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Catch | Catch | ||
| { | { | ||
| - | $CheckDate = Get-Date -Format | + | $CheckDate = Get-Date -Format G |
| Add-Content -Path " | Add-Content -Path " | ||
| } | } | ||
| Ligne 538: | Ligne 560: | ||
| # Suppression du lien de shadowcopy | # Suppression du lien de shadowcopy | ||
| - | cmd /c rmdir C: | + | (Get-Item -Path C: |
| } | } | ||
| Ligne 746: | Ligne 768: | ||
| Else | Else | ||
| { | { | ||
| - | | + | |
| exit $ExitCode | exit $ExitCode | ||
| } | } | ||
| - | echo " | + | Write-Host |
| exit $ExitCode | exit $ExitCode | ||
| </ | </ | ||
| - | |||
| - | --- // | ||
| ~~DISCUSSION~~ | ~~DISCUSSION~~ | ||