-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackupOfPrintQ.ps1
36 lines (35 loc) · 1.17 KB
/
BackupOfPrintQ.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Variables
#---------------------------------
$ServersPrintList = <#File with a list of print servers#>
$PathPrint = <#Path to save#>
$Now = Get-Date
$Now2 = Get-Date -Format dd.MM.yyyy
$Days = "35"
#---------------------------------
#Delete old backups
#---------------------------------
$LastWrite = $Now.AddDays(-$Days)
$Files = Get-Childitem $PathPrint -Recurse | Where{$_.LastWriteTime -le "$LastWrite"}
foreach ($File in $Files)
{
if ($File -ne $NULL)
{
write-host "Deleting File $File" -ForegroundColor "DarkRed"
Remove-Item $File.FullName | out-null
}
else
{
Write-Host "No more files to delete!" -foregroundcolor "Green"
}
}
#---------------------------------
# Execute the code of backup for each server in the list
#---------------------------------
Get-Content $ServersPrintList | ForEach-Object {
$ServerName = $_
$Item = $PathPrint + $ServerName + "_" + $Now2 + ".printerExport"
if (Test-Path($Item)) { Remove-Item $Item }
$Command = "C:\Windows\System32\spool\tools\PrintBrm.exe -s \\$ServerName -b -f $Item"
Invoke-Expression $Command
}
#---------------------------------