Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Script 1
  2. $UsersFolder = $env:PUBLIC -replace "Public" # должно заканчиваться на \
  3. $filename = 'filename.ext'
  4. $InputFolder = 'path\to\unpitfolder'
  5. $Users = Import-Csv -Path 'path\to\userlist.csv' # userlist.csv Поля: Name
  6. foreach ($user in $users)
  7. {
  8.  if (Test-Path -path "$UsersFolder$($user.Name)\AppData\$filename")
  9.  {
  10.   Copy-Item -Path "$UsersFolder$($user.Name)\AppData\$filename" -Destination "$inputfolder\$($user.Name)_$filename" -Force -ErrorVariable Err -ErrorAction SilentlyContinue
  11.   if (!$err) {Remove-Item -Path "$UsersFolder$($user.Name)\AppData\$filename" -Force}
  12.   else {"Не удаётся скопировать файл $UsersFolder$($user.Name)\AppData\$filename в $inputfolder\$($user.Name)_$filename."}
  13.  }
  14. }
  15.  
  16.  
  17. # Script 2
  18. $OutputFolder = "path\to\outputfolder"
  19. $OldServer = "e:\OldServer"
  20. $Users = Import-Csv -Path 'path\to\userlist.csv' # userlist.csv Поля: Name
  21. foreach ($user in $users)
  22. {
  23.  if (Test-Path -Path "$OutputFolder\$($user.Name)*")
  24.  {
  25.   $UserFiles = Get-ChildItem -Path "$OutputFolder\$($user.Name)*"
  26.   Foreach ($userfile in $userfiles)
  27.   {
  28.    $NewName = $userfile.Name -replace "$($user.Name)_"
  29.    Copy-Item -Path $userfile.Fullname -Destination "$OldServer\$NewName" -Force -ErrorVariable Err -ErrorAction SilentlyContinue
  30.    if (!$err) {Remove-Item -Path $Userfile.Fullname -Force}
  31.    else {"Не удаётся скопировать файл $($Userfile.Name) в $OldServer\$NewName."}
  32.   }
  33.  }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement