-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvancedCopyRemoteDesktopFiles.ps1
More file actions
47 lines (36 loc) · 1.96 KB
/
advancedCopyRemoteDesktopFiles.ps1
File metadata and controls
47 lines (36 loc) · 1.96 KB
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
39
40
41
42
43
44
45
46
47
# Prompt for domain credentials
$credential = Get-Credential -Message "Enter domain credentials"
# Prompt for the username
$username = Read-Host "Enter the username"
# Prompt for the remote computer name
$remoteComputerName = Read-Host "Enter the remote computer name"
# Define source folders and target folder
$sourceFolders = @("Desktop", "Documents", "Pictures", "Downloads", "Videos")
$targetBaseFolder = "\\sterling1.sbt.local\d$\USER\$username\Remote Desktop Files"
# Define file extensions to copy
$mediaExtensions = @("*.jpg", "*.jpeg", "*.png", "*.bmp", "*.gif", "*.mp3", "*.mp4", "*.avi", "*.mkv", "*.mov", "*.txt", "*.doc", "*.docx", "*.xls", "*.xlsx", "*.ppt", "*.pptx", "*.pdf")
# Convert the credentials to a PSCredential object for use with the NET USE command
$netCredential = New-Object System.Management.Automation.PSCredential($credential.UserName, $credential.Password)
# Map the remote user's folder using the given credentials
$remoteUserFolder = "\\$remoteComputerName\c$\users\$username"
net use $remoteUserFolder ($netCredential.GetNetworkCredential().Password) /user:$($netCredential.UserName) /persistent:no
# Copy media and document files from source folders to the target folder
foreach ($folder in $sourceFolders) {
$sourceFolder = "$remoteUserFolder\$folder"
$destinationFolder = "$targetBaseFolder\$folder"
if (!(Test-Path $destinationFolder)) {
New-Item -ItemType Directory -Path $destinationFolder
}
foreach ($ext in $mediaExtensions) {
Get-ChildItem -Path $sourceFolder -Filter $ext -Recurse -Force -ErrorAction SilentlyContinue | ForEach-Object {
try {
Copy-Item -Path $_.FullName -Destination $destinationFolder -ErrorAction Stop
} catch {
Write-Warning "Failed to copy $($_.FullName): $($_.Exception.Message)"
}
}
}
}
# Disconnect the network drive
net use $remoteUserFolder /delete
Write-Host "Media and document files copied successfully"