PowerShell to Robocopy exclude is not working - powershell

In PowerShell I am trying to copy files from one location to another and want some files to be excluded. so I am using the following commands:
$Excludefiles="`"$((get-content 'C:\WorkingDirectory\List.txt') -join'""')`""
robocopy "C:\aa\" "C:bb\" /XF $Excludefiles
It seems it is excluding everything.
Please share your thoughts.

Related

Powershell script to delete temp files in a specified folder and then create logging in a seperate folder

Can someone please help me with Powershell script.
The task is to delete temp files in a specified folder and then create logging in a seperate folder.
Also, the windows batch file (.bat) I add my code always prompts, "Are you sure (Y/N)?". How can I disable this? And there is no log file being created in the end.
Thanks in advance!
Bobby
I tried this script.
Del C:\Users\redla\Downloads\C_drive*. -recurse -force; Start-Transcript -Append C:\Users\redla\Downloads\test\Log.txt*
It works fine in Powershell but when I add it to a .bat file, it works with the deletion part but doesn't create the log file in my specified folder.

Run Robocopy in "Report Only" Mode

I have a fairly simple robocopy command here that I want to run that will upload files to an Azure storage account. The problem I have is I'm looking at approxiately 70,000 files but a lot of these already exist in the storage account.
What I want to do is run the command in a "Log Only" or "whatif" mode so I can see how many files will be copied and how many will be skipped. This command gives that detail but will perform the copy. Is there a switch I can add that will simply provide the log and NOT copy the files?
S:\inbound\ \\<storageaccount>\<filesharename>\inbound\ /r:3 /w:3 /e /xo /xx /LOG:Robocopy_20200313_Manual.txt
Yes, you may try the switch /L which means List Only but Will Not Copy any files or Change any attributes.

Using xcopy instead of robocopy for wildcarded files

I'm working on an old 2003 server and I want to copy a folder for specific files while also retaining the folder structure.
Note: I am not allowed to install or add robocopy onto this server.
The command that I use on another server is usually something like this.
robocopy Application Application_small *.txt /E
This, of course, gives me a new directory with nothing but the .txt files and the same folder structure.
But of course, robocopy isn't on Server 2003. However, xcopy does exist. Is there an equivalent switch that I can use to get the same kind of result as robocopy?
Similar question was found here.
xcopy Application\*.txt Application_small /s

Powershell Copy-item command not working in script although it does work when run from a command line

I am on a Windows 7 machine trying to execute a PowerShell script to copy a template directory to another directory. The command I am executing looks like:
Copy-Item -path "$projectsFolder$SourceFolder" -destination "$Test" -recurse -verbose;
The parameters are as follows:
path: C:\Users\username\Documents\Visual Studio 2010\Projects\TemplateSolution\Source
Destination: C:\Users\username\Documents\Visual Studio 2010\Projects\test\source\main
When I run this command at a PowerShell prompt, the files are copied correctly. If I try and execute the command in the script with verbose enabled, it appears to copy the files and directories, but only the top level directory is created in the file system. I am not sure why this would happen and I would appreciate any guidance or troubleshooting steps to perform.
Make sure you put quotes around the directory names if they have spaces in them. Also, you may need the -Force parameter to create destination directories if they do not exist.

please give the command in Robocopy i should use to copy the files from primary server to the secondary server

I got the command in robocopy as mentioned below
ROBOCOPY Source Destination [file…[file]…..] [Options]
Source: Source Directory
Destination: Destination Directory
Files: files to copy .
Please let us know what does the "\server\share\path" means? Kindly provide me an example on this command syntax and explain
An example of a ROBOCOPY call would be
ROBOCOPY C:\Users \\SERVER\backup\Users /MIR /R:0 /W:0
This copys everything under C:\Users to a network share at the UNC path \\SERVER\backup. If you don't know, what that means, google for 'UNC path' or find a nice tutorial that explains how to setup network shares under Windows.
Instead of \\SERVER\backup, that copies to a remote machine, you are totally free to use something like H:\ to copy to a local drive like a USB mass storage device.
The part /MIR /R:0 /W:0 are options of ROBOCOPY. Call ROBOCOPY /? to get an explanation for these.
Cheers,