Search code examples
windowspowershellbatch-filestartupscript

Startup script to generate uninstall command


I have a text file of the format:

computername1 uninstallkey1
computername2 uninstallkey2
...
computername200 uninstallkey200

I am trying to write a startup script (batch file or powershell?) that generates a msiexec command that looks up and implants the correct key for each computer it executes on e.g.:

msiexec /x install.msi key=uninstallkey

If I have not made anything clear, please ask and any help is much appreciated!


Solution

  • @ECHO OFF
    SETLOCAL
    FOR /f "tokens=1*" %%i IN (yourtextfilename.txt) DO (
     IF /i %%i==%COMPUTERNAME% ECHO MSIEXEC /x install.msi key=%%j
    )
    

    This should do as you require - yourtextfilename.txt contains the data, presumably on a shared drive; finds the line where the computername in column 1 is the same as the computername returned by %computername% in the target computer's environment.

    (all case-insensitive EXCEPT %%i and %%j which must match and be the same case)

    Command simply ECHOed - remove the ECHO keyword after verification to activate.