Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script 1
- $UsersFolder = $env:PUBLIC -replace "Public" # должно заканчиваться на \
- $filename = 'filename.ext'
- $InputFolder = 'path\to\unpitfolder'
- $Users = Import-Csv -Path 'path\to\userlist.csv' # userlist.csv Поля: Name
- foreach ($user in $users)
- {
- if (Test-Path -path "$UsersFolder$($user.Name)\AppData\$filename")
- {
- Copy-Item -Path "$UsersFolder$($user.Name)\AppData\$filename" -Destination "$inputfolder\$($user.Name)_$filename" -Force -ErrorVariable Err -ErrorAction SilentlyContinue
- if (!$err) {Remove-Item -Path "$UsersFolder$($user.Name)\AppData\$filename" -Force}
- else {"Не удаётся скопировать файл $UsersFolder$($user.Name)\AppData\$filename в $inputfolder\$($user.Name)_$filename."}
- }
- }
- # Script 2
- $OutputFolder = "path\to\outputfolder"
- $OldServer = "e:\OldServer"
- $Users = Import-Csv -Path 'path\to\userlist.csv' # userlist.csv Поля: Name
- foreach ($user in $users)
- {
- if (Test-Path -Path "$OutputFolder\$($user.Name)*")
- {
- $UserFiles = Get-ChildItem -Path "$OutputFolder\$($user.Name)*"
- Foreach ($userfile in $userfiles)
- {
- $NewName = $userfile.Name -replace "$($user.Name)_"
- Copy-Item -Path $userfile.Fullname -Destination "$OldServer\$NewName" -Force -ErrorVariable Err -ErrorAction SilentlyContinue
- if (!$err) {Remove-Item -Path $Userfile.Fullname -Force}
- else {"Не удаётся скопировать файл $($Userfile.Name) в $OldServer\$NewName."}
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement