How to add a skip or loop to robo copy - robocopy

I have a robo copy script that connects to a PC and moves the file to a certain folder. This script does this for 188 PC's, the problem I am having is that if the PC is turned off the script gets stuck on retrying for that PC. How do i add a skip so that the process can move to the next copy.
I am unfamiliar with robo copy so i am not sure.
sample script.
robocopy \\PC123\c$\Glory\Archive \\ad.corp.com\files\corp\public\glory\tpblm2/mir /log+:robocopy.log /xf robocopy.log /np /tee

Related

Remove-Item in powershell

The file still exists (because I can open it through powershell) but Remove-Item isn't able to find the location apparently. Do you have any idea why?
Looks like like you hit a similar problem I recently ran into. In my case I had a space at the end of a folder name, and Windows absolutely refused to delete it.
Turns out Windows has an alternate method for addressing files and folders where you have to prefix the path with \\?\.
In your case, probably need to try this:
Remove-Item "\\?\$Profile"
In my case I was working in the command prompt at the time and RD /Q /S "\\?\FilePath" worked. So if worst comes to worst, you might do a Write-Host $Profile, select and copy the resulting path, switch to the command prompt and try the RD /Q /S command.
In your case, what is causing the problem is almost certainly the special characters after the OneDrive\ in the path.

Bat Backup Script

What I am trying to do is to backup a user profile from their local workstation to our backup servers and send me an email once it's complete. I currently have this is two different scripts. It would be nice if we could make this in one script. If I need two scripts, that won't be a problem.
The first script is the backup, and it has been working just fine.
robocopy C:\Users\TravisWhiteman.ArchwaySys\AppData \\10.1.10.6\WorkstationBackup\Test\AppData /mir /W:3 /R:1 /log:CopylogAppData.txt
robocopy C:\Users\TravisWhiteman.ArchwaySys\Desktop \\10.1.10.6\WorkstationBackup\Test\Desktop /mir /W:3 /R:1 /log:CopylogDesktop.txt
robocopy C:\Users\TravisWhiteman.ArchwaySys\Documents \\10.1.10.6\WorkstationBackup\Test\Documents /mir /W:3 /R:1 /log:CopylogDocuments.txt
robocopy C:\Users\TravisWhiteman.ArchwaySys\Downloads \\10.1.10.6\WorkstationBackup\Test\Downloads /mir /W:3 /R:1 /log:CopylogDownloads.txt
Now I want to add in a few features, and I don't know how. I want to change it from manually setting the user profile directory to the system automatically find out who the user is. I think it's something like %USERNAME%. The goal is having the system figure the user out is so I don't have to change the C:\Users\TravisWhiteman.ArchwaySys for every workstation. All of our workstations turns on automatically, 10 min before the scheduled task to backup, in case a user were to shut off their computer.
Basically, what you need is the profile path of the currently logged on user for a list of remote computers.
Steps for each computer:
Get the currently logged on user's login name (here is the method I currently use)
Get the SID for this user - let's say $userSID (a method is described here)
Browse this registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$userSID on the remote computer, and read the value ProfileImagePath, it holds the local profile path for this user on this computer (example of remote registry access)
Convert the local path to a network path (C:\Users\... -> \\computerName\c$\Users)
Call robocopy and get some coffee (removed coffee from loop)
One could simply go for \\computer\c$\Users\$userLogin but as OP's example demonstrates it, Windows sometimes appends your domain name to your user name in your local profile folder name, in quite an unpredictable fashion.
(the Remote Registry service must be running on the remote computers)
If the workstation was shut down and then awoken, you I'd target the last modified folder in C:\Users.

How do I issue a remote copy command?

The script I'm working on right now performs a bunch of work on the email server for processing Litigation hold requests. One of the components of this script is to copy all the data from an identified folder on a file server to a secure backup location that can't be altered which happens to reside on the same remote server. I have the script working fine but it copies all the files across the network from the file server to the email server where the PowerShell script is run and then pushes it right back to the same file server it came from to the "hold" folder. This is creating severe delays as some of these folders are several thousands of files ranging from a few bytes to several meg each.
I'm looking for a way for my PowerShell script running on the email server to issue a remote command to the file server to copy a folder from one directory to another (all on the same remote server). Any suggestions?
Currently, I'm using the robocopy command in my script but I'm open to other ways of performing this.
robocopy "Source Folder" "Destination Folder" /e
I'm looking for something like:
PSEXEC \\\FileServer -s -d Copy "Source folder" to "Destination folder"
I just can't seem to find any material on the old google train that satisfies the situation.
psexec \\fileserver -s robocopy "source" "destination" /e
should work just fine. With PSRemoting enabled on the fileserver you could also do
Invoke-Command -Computer fileserver -Scriptblock {
& robocopy "source" "destination" /e
}
Note that this assumes local paths on the remote server. If you're working with network shares on the remote host you'll be running into the second hop problem.
For some strange reason the first attempt to use PSEXEC prior to posting resulted in an error stating it didn't know how to handle the command. But I plugged in the PSEXEC command again and it worked perfectly today.
Thank you.

PowerShell Freeze on File System Copy

For some when I run this command in PowerShell, it succeeds up to a certain point:
Copy-Item S:\schools\$question C:\Users\$env:username\Desktop\schools\$question -Recurse -Verbose
Integrated with my current script, this line takes the files from S:\schools\$question and copies them to C:\Users\$env:username\Desktop\schools\$question. This works fine on some folders, and then just stops running on other ones. On the one's that it stops running on, PowerShell seems to be using 50% of my CPU resources, whitch should never happen as I'm just copying files.
Again, as always, any assistance is greatly appreciated.

Want to wait till copy complete using Powershell Copy-Item

I am copying files from One Windows machine to another using Copy-Item in Powershell script.
But I want to wait till copy completes, Powershell Copy-Item is non-blocking call means, it just triggers copy and returns to script however I want to wait till copy completes.
Is there any way to do it ?
Maybe "copy-item [...] | out-null" will help to wait for completion.
"Out-null actually deletes output instead of routing it to the PowerShell console, so the script will sit and wait for the content to be deleted before moving on."
The explanation comes from ITProToday.com:
https://www.itprotoday.com/powershell/forcing-powershell-wait-process-complete
Copy-Item does block. I just copied a 4.2GB file from a share on our gigabit network to my local machine. My PowerShell prompt hung and didn't return for several minutes.
It seems like it's non-blocking here for very small files. I'm using:
Start-Sleep -s 3
To wait for the files to be copied. Not an ideal solution but it's what I got so far.