create batch file to delete files from a specific model computer

I would like to create a batch file that first determines the model of the laptop/desktop and then based on the result, deletes certain files/folders on that PC.  I want this to run on startup on a new computer setup.  So for example, I would have the batch file run "wmic computersystem get model."  Then based on the result of "get model", I want the script to then delete specific files/folders on the C: drive.
boshenskaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
Try this; it reads the model into the variable "Model" and then jumps to the respective section.
The sections are defined in the "Jump"-variables at the beginning, so if you have different model names, but want to run the same cleanup, you can just point them to the same section.
If the section is not found, the script will exit with errorlevel 1.
@echo off
setlocal enabledelayedexpansion
set Jump[Virtual Machine]=MSVirtualMachine
set Jump[Whatever]=Whatever
for /f "delims=" %%a in ('wmic.exe computersystem get model /value ^| find.exe "="') do set %%a
echo Model: [%Model%]
if not "!Jump[%Model%]!"=="" goto !Jump[%Model%]!
echo This model is not supported by this script: [%Model%]
exit /b 1

:MSVirtualMachine
echo Maintaining '%Model%' in section '!Jump[%Model%]!' ...
REM ...

goto :eof

:Whatever
echo Maintaining '%Model%' in section '!Jump[%Model%]!' ...
REM ...

goto :eof

Open in new window

0
boshenskaAuthor Commented:
I will give this a try...thanks
0
boshenskaAuthor Commented:
could you give me an example of this...in other words, the models would be Dell OptiPlex 990, 9010, 9020, Latitude E6440,E6540.  Would I enter all of those in the "model" section?  What I need is something that detects the model, for example "Dell OptiPlex 990"....if it determines it is a 990, then I want specific folders deleted in C:\TEMP.  If it determines it is a 9010, then I need it to delete folders in C:\TEMP as well.  Hope that makes sense.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

oBdACommented:
Just run the script as it is on these machines; you'll get the model name inside square brackets, say "Optiplex 990" and "Optiplex 9010", and an error message which you can ignore.
Then you'd add one variable "Jump[<Model>]" for each model, with a target label as value. The target label can be any label where the maintenance tasks you want will be executed.
In this example, it would use the same code section for the 990 and 9010:
@echo off
setlocal enabledelayedexpansion
set Jump[Virtual Machine]=MSVirtualMachine
set Jump[Optiplex 990]=DellOptiplex
set Jump[Optiplex 9010]=DellOptiplex
for /f "delims=" %%a in ('wmic.exe computersystem get model /value ^| find.exe "="') do set %%a
echo Model: [%Model%]
if not "!Jump[%Model%]!"=="" goto !Jump[%Model%]!
echo This model is not supported by this script: [%Model%]
exit /b 1

:MSVirtualMachine
echo Maintaining '%Model%' in section '!Jump[%Model%]!' ...
rd /s /q C:\Temp\Acme
REM ...
goto :eof

:DellOptiplex
echo Maintaining '%Model%' in section '!Jump[%Model%]!' ...
rd /s /q C:\Temp\Foo
rd /s /q C:\Temp\Bar
REM ...
goto :eof

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
oBdACommented:
On a side node: you don't need to logon locally to the machines in question, you can retrieve the Model remotely with /node:
wmic.exe /node:SomeComputerName computersystem get model /value

Open in new window

0
boshenskaAuthor Commented:
I am going to add some more models...but so far, it works great...thanks for the help!!
0
boshenskaAuthor Commented:
this was a big help!!  Thank you.
0
boshenskaAuthor Commented:
what command can be used at the end of this script to have it delete itself?  I wan this to run one time at first logon after desktop/laptop has come out of sysprep.
0
oBdACommented:
Replace all "goto :eof" with "goto DeleteMe", and add this at the end of the script:
:DeleteMe
del "%~f0"

Open in new window

It'll show an error that it can't find the script (because cmd will try to continue with the next line of the deleted script), but it will happily delete itself - so make sure you have a backup before you start testing ...
The example script from above would look like this:
@echo off
setlocal enabledelayedexpansion
set Jump[Virtual Machine]=MSVirtualMachine
set Jump[Optiplex 990]=DellOptiplex
set Jump[Optiplex 9010]=DellOptiplex
for /f "delims=" %%a in ('wmic.exe computersystem get model /value ^| find.exe "="') do set %%a
echo Model: [%Model%]
if not "!Jump[%Model%]!"=="" goto !Jump[%Model%]!
echo This model is not supported by this script: [%Model%]
exit /b 1

:MSVirtualMachine
echo Maintaining '%Model%' in section '!Jump[%Model%]!' ...
rd /s /q C:\Temp\Acme
REM ...
goto DeleteMe

:DellOptiplex
echo Maintaining '%Model%' in section '!Jump[%Model%]!' ...
rd /s /q C:\Temp\Foo
rd /s /q C:\Temp\Bar
REM ...
goto DeleteMe

:DeleteMe
del "%~f0"

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.