I am trying to create a script on Windows which when run on an admin PC:
Copies a folder from the admin PC into a group of network PCs by specifying the ip address / range
For each destination PC, Navigate into the folder and run another script file.
Using the method described by seanyboy here:
net use \\{dest-machine}\{destfolder} {password} /user:{username}
copy {file} \\{dest-machine}\{destfolder}
I'm not sure on how i can write a 'for' loop to go through each 'dest-machine' and perform step 2. Any ideas would be greatly appreciated.
check Robocopy:
ROBOCOPY \\server-source\c$\VMExports\ C:\VMExports\ /E /COPY:DAT
make sure you check what robocopy parameter you want. this is just an example.
type robocopy /? in a comandline/powershell on your windows system.
Below command will work in command prompt:
copy c:\folder\file.ext \\dest-machine\destfolder /Z /Y
To Copy all files:
copy c:\folder\*.* \\dest-machine\destfolder /Z /Y
Why for? What do you want to iterate? Try this.
call :cpy pc-name-1
call :cpy pc-name-2
...
:cpy
net use \\%1\{destfolder} {password} /user:{username}
copy {file} \\%1\{destfolder}
goto :EOF
Regarding step 2., check manual for psexec command (sysinternal tools)
Related
How to copy files from one server to another server(VM) using a windows batch command. ?
I have used below command
syntax : xcopy \\source_path \\serverIP\Destination_path /s /a /d
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
I'm getting the below error "Invalid drive specification" as of now.
Do I need to give credentials for accessing the VM ? If yes then where and how?
I have checked the destination path is correct.
Is there any other command should be used in that case ?
Do I need to give credentials for accessing the VM ? If yes then where and how?
If the passwords on the source and target machine are the same then no credentials are necessary, otherwise yes they will need to be provided. Two solutions you can consider:
Use "runas" and specify the credentials there
Use the temporary network drive solution proposed in the comment by UserPo41085. This solution uses the "net view" command which has credential parms.
I have checked the destination path is correct.
example : xcopy \\c:\repo\testproject \\10.101.101.11\C:\test\project /s /a /d
Both paths in the example provided are a mixture of standard "DOS" paths and UNC paths. UNC paths reference a share name and not a disk letter.
The example in the link below copies a file on the local machine called zz_yuv.png to a machine called "ws9" which has a share called "c9.system" and the share is mapped to the root folder of the c: drive on ws9. If you are running an account which is a member of the administrators group you can use the admin shares...(admin$, c$ etc.)
xcopy example
Is there any other command should be used in that case ?
Robocopy is built into the later versions of windows. It does come with a learning curve but is much more robust than xcopy. Just as a note, robocopy will be under the same types of credentialing restraints as xcopy - it just has more and better features for copying.
I am trying to use a cmd command for all folder and its subfolder.
cacls "F:\Testing\*" /e /c /d %username%
all the folders and files in Testing are affected but the sub folders of those affected folder
F:\Testing\Folder\a
F:\Testing\Folder\b
etc..
are not affected by the command.
I also try
cacls "F:\Testing\*\*" /e /c /d %username%
but it does not work either.
Is there any wildcard that work for all sub-sub-... folders?
I've never used the CACLS command, but the built in help (cacls /?) indicates you want the /T option.
/T Changes ACLs of specified files in
the current directory and all subdirectories.
Whenever you have a question on how to use a Windows console command, you should always first check the built in help. Nearly all commands support the /? option to display help.
I have a script that runs in WinPE that takes a system drive with Windows installed and deletes everything off of the drive (keeping the filesystem intact).
When dealing with a Windows XP/Vista/7 installation it functions properly. attrib -S -A -H -I -R /S /D \ is run, and then everything is deleted.
However, within Windows 8, I run into an "Access Denied" error. For some reason, even as the SYSTEM user within WinPE, I can't edit the directory C:\ProgramData\Microsoft\Windows\LocationProvider. I can't use attrib to set attributes, I can't delete it - I can't even cd into it! dir /a just returns File Not Found.
Using rmdir /S /Q gives me the "Access Denied" error.
Assuming that the problem is related to permissions and/or ownership, you can work around it using the built-in robocopy tool - luckily, this is included in Windows PE.
First, create an empty directory, e.g., x:\empty and then run
robocopy /e /purge /b x:\empty c:\
The /b flag tells robocopy to use backup mode, which bypasses security.
Had the same problem. You need to take ownership first, for example using takeown.exe. Then fix permissions, for example using icacls.exe. Then proceed as you wish with copy, move, delete.
I'm trying to run a basic forfiles command, but no matter what mask I use it always simply prints the whole content of the directory. Not filtered for *.bat no "is a batch file", just a simple list off all files in C:\
I'm working on a winXPproffesional. What could be the cause?
forfiles /p c:\ /s /m *.bat /c "cmd /c echo #file is a batch file"
Somehow this version uses a different syntax:
FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo #file is a batch file"
works!
The command should work.
Maybe you have a FORFILES.BAT, FORFILES.CMD or bogus copy of FORFILES.EXE in either your current directory or another directory that happens to be in your PATH.
Try running this command from the command line to verify that the correct FORFILES.EXE is executing.
for %F in (forfiles.exe forfiles.bat forfiles.cmd) do #echo %~$path:F
If that is not the problem, then it looks to me like you have a bugged version of FORFILES.
Try using one option at a time to see which, if any of the options work
As a matter of fact, there's no forfiles in Windows XP but there is one in Windows 2003 Server, with the syntax as in your question.
Windows 2000 did have the tool, but only in the form of a resource kit, which had to be downloaded separately. For some reason, the corresponding Technet article doesn't list forfiles as part of the kit, although, as can be derived from this and this article, it must have been there initially. Maybe the guys at Microsoft decided to stop distributing the older version to avoid possible confusion with the newer one.
And yes, it seems like your forfiles copy is the older version, which does have a slightly different syntax, as explained in this post.
What's the best way to copy a file from a network share to the local file system using a Windows batch file? Normally, I would use "net use *" but using this approach how can I get the drive letter?
Can you just use the full UNC path to the file?
copy \\myserver\myshare\myfolder\myfile.txt c:\myfiles
You can specify the drive letter for net use. Put this in the command prompt for more info:
net use /?
You can also use xcopy and robocopy:
xcopy "\\server\share\path" "destination"
robocopy "\\server\share\path" "destination"