Scipt to copy folder and delete another

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jpulse
Posts: 1
Last visit: Thu Oct 05, 2017 5:51 am

Scipt to copy folder and delete another

Post by jpulse »

I created a .bat file that will do what I want, but I am looking for a script that will appear more user friendly and cleaner. The script I wrote copies a folder from a computer to another computer based on user input, then once that is done it will delete a specified folder out of the all user profiles based on the what the user input previously as the "To" computer.

echo What computer are you copying the files FROM?
SET /p FromComputerName=
echo What computer are you copying the files TO?
Set /p ToComputerName=
xcopy /E /I /Y "\\%FromComputerName%\c$\ProgramData\test" "\\%ToComputerName%\c$\ProgramData\test"

RD /S /Q "\\%ToComputerName%\c$\Users\%username%\AppData\Roaming\test"

How can I create a vbscript that will do the exact same thing as my .bat file with a user input box?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scipt to copy folder and delete another

Post by jvierra »

Use PowerShell as it is easier to learn.

VBScript is obsolete. Forget about learning it as a first scripting language.

Learn PowerShell: https://mva.microsoft.com/en-us/trainin ... shell-8276
User avatar
mxtrinidad
Posts: 399
Last visit: Tue Aug 06, 2024 5:37 am

Re: Scipt to copy folder and delete another

Post by mxtrinidad »

Or, as JVierra said... Learn and use PowerShell:

Here's how it would look using both PowerShell with the DOS command you provided, as in PowerShell you can run most (if not all) of the DOS Command:

$SourceComputer = "Computer1"; $TargetComputer = "Computer2";
$SourcePath = "\\$SourceComputer\" + 'c$' + "\ProgramData\Test";
$TargetPath = "\\$TargetComputer\" + 'c$' + "\ProgramData\Test";
Write-Host "Copy from $SourcePath to $TargetPath";
xcopy /E /I /Y $SourcePath $TargetComputer

$TargetToUsers = "\\$TargetComputer\" + 'c$' + "\Users\$env:UserName\AppData\Roaming\test";
RD /S /Q $TargetToUsers

Feel free to open the PowerShell Console and start using the following commands:
1. List all help topics by typing:
Get-Help About_* | Select name

2. Pick a topic, and execute:
Get-Help about_Windows_PowerShell_5.0 -Detailed

This will get you started as PowerShell provide with help topics, as long as you've run as Administrator the command:
Update-Help -force

Again, JVierra gave you the Microsoft Academy link to access PowerShell Online Training.
Take advantage of it.

Welcome to PowerShell!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scipt to copy folder and delete another

Post by jvierra »

Hi Max. I wanted to leave it as a good first project in PosH. Need is the mother of invention and also a very good stimulus to the brain for learning.

Yes - help is a good way to start but I prefer a more structured entry for the absolute beginner or things will get very confusing very fast. This tends to lead to frustration.

PowerShell is fun to learn and it is actually quite easy with a decent structured training source. The MVA is excellent and gets you up and running in less than two hours with more if you need it.

I am an old VBScripter but it is not a good tool for learning as it is slowly being retired.
This topic is 7 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked