Compare cert salaries and plan your next career move
Everyone wrote: » Yes it is possible. Obviously it will take you longer to figure out how to write a powershell script to do this, than it would to just use robocopy, but it can be done. Something like this... $destination = <where you want the files to get copied to> $data = Get-ChildItem <where you are copying files from> ForEach ($object in $data) { Copy-Item $object.Name -destination $destination } Now if you want to copy folders, you can use the -recurse option. Synchronization will require checking the difference on the LastWriteTime, which will require use of the Get-Date command and some "If" statements. Once you get it all figured out, you can set your powershell script up as a scheduled task to run once a day. That should be enough to get you started, good luck.
[B][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0]Get-ChildItem [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]C:\Users\rkaucher\Documents[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] | [/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0]Copy-Item [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][I][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0]-Destination [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]C:\backup\[/COLOR][/SIZE][/FONT] [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
[B][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0]gci [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]C:\Users\rkaucher\Documents[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] | [/SIZE][/FONT][/SIZE][/FONT][B][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0]cp [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B][I][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0][FONT=Courier New][SIZE=2][COLOR=#5f9ea0]-Destination [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/I][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]C:\backup\[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
RobertKaucher wrote: » Oh, and don't forget Where-Object!gci C:\Users\rkaucher\Documents | Where {$_.LastWriteTime -gt (Get-Date).AddDays(-1) } | cp -Destination C:\backup\
Robocopy d:\data\folder1 \\server\d$\data\folder1 /e /z /copyall /dcopy:T /r:2 /w:5 /log:d:\log\folder1.txt /v /tee
Claymoore wrote: » Copy-Item does not copy the NTFS file permissions, which I assume you want. You could write a crazy PoSh script that included cacls, but scripting is supposed to make your life easier so Robocopy is the right tool in this case. Try:
Everyone wrote: » Fixed that for ya. If you're going to shorten things with aliases, go all the way! Yes I tend to write my scripts in an easy to read format. When I'm just issuing commands, I'd do it like that.
RobertKaucher wrote: » I understand completely. I didn't want people to think I was correcting you. Now some people never use the proper PoSh style syntax, though, because they learned C# or Perl or some similar language first and it acts as a handicap to them - and they never get to see how powerful it can be right at the shell. They only think of it as "scripting". I had to educate a Unix guy at work regaring that. He basically said it was too wordy to ever be useful as a proper shell language.
Compare salaries for top cybersecurity certifications. Free download for TechExams community.