Created
September 28, 2023 10:28
-
-
Save lquenti/7c645e3ff0e6a554f4b8f21ca912eb78 to your computer and use it in GitHub Desktop.
Exclude AppData from TSM tivoli backups using powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
A script to write an exclude file for all users AppData for TSM Tivoli. | |
Copyright Lars Quentin 2023, licsensed as CC0 (Public Domain) | |
#> | |
<# | |
Configuration Variables: | |
- BASE_PATH: | |
Where the user folders are. | |
- GLOBAL_REGEX_PATTERN: | |
The "Regular Expression" pattern that filters which user folders are relevant. | |
If all are relevant, you can use the RegEx "^.*?$". | |
- OUTPUT_FILE_PATH: | |
Where the generated tivoli file should be saved. | |
Note that you need to have write access in that parent folder. | |
#> | |
$BASE_PATH = "C:\Users\" | |
# This RegEx matches a string that contains exactly 5 lower- or uppercase letters. | |
# If numbers are also relevant: "^[a-zA-Z0-9]{5}" | |
$GLOBAL_REGEX_PATTERN = '^[a-zA-Z]{5}$' | |
# Match everything. | |
# $GLOBAL_REGEX_PATTERN = '^.*?$' | |
$OUTPUT_FILE_PATH = ".\EXCLUDE_LIST.txt" | |
<# end configuration, begin of program #> | |
function GetMatchedDirectories { | |
param ( | |
[string]$BasePath, | |
[string]$RegexPattern | |
) | |
$matchedDirectories = Get-ChildItem -Path $BasePath | | |
Where-Object { $_.PSIsContainer -and $_.Name -match $RegexPattern } | | |
Where-Object { Test-Path (Join-Path $_.FullName "AppData") } | | |
ForEach-Object { $_.FullName } | |
return $matchedDirectories | |
} | |
function WriteStringToFile { | |
param ( | |
[string]$MatchedDir | |
) | |
$stringToWrite = "exclude ${MatchedDir}\AppData" | |
Add-Content -Path $OUTPUT_FILE_PATH -Value $stringToWrite | |
} | |
function Main { | |
$matchedDirs = GetMatchedDirectories -BasePath $BASE_PATH -RegexPattern $GLOBAL_REGEX_PATTERN | |
foreach ($dir in $matchedDirs) { | |
Write-Host $dir | |
WriteStringToFile -MatchedDir $dir | |
} | |
} | |
Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment