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!

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Peter for such a speedy and tidy answer, you've saved me hours! Thanks again,
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" 
    } 
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.