1

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!

Davor Josipovic
  • 5,296
  • 1
  • 39
  • 57

2 Answers2

2
@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.

Magoo
  • 77,302
  • 8
  • 62
  • 84
1

In PowerShell,

$comp = Import-CSV -Delimiter " " -Path C:\comp.txt -Header computername,uninstallkey
$comp | ForEach-Object { 
    if ($env:COMPUTERNAME -eq $_.Computername) { 
        Start-Process -FilePath "msiexec.exe" -ArgumentList "/x install.msi key=$_.uninstallkey" 
    } 
}
ravikanth
  • 24,922
  • 4
  • 60
  • 60