生成卸载命令的启动脚本



我有一个文本文件,格式为:

computername1 uninstallkey1
computername2 uninstallkey2
...
computername200 uninstallkey200

我正在尝试编写一个启动脚本(批处理文件或powershell?),生成一个msiexec命令,查找并植入正确的密钥,为每台计算机执行,例如:

msiexec /x install.msi key=uninstallkey

如果我有什么不清楚,请问,任何帮助是非常感激的!

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

这应该按照您的要求做- yourtextfilename.txt包含数据,可能在共享驱动器上;查找第1列中的计算机名与目标计算机环境中%computername%返回的计算机名相同的行。

(所有不区分大小写的EXCEPT%%i%%j必须匹配且大小写相同)

命令简单ECHO ed -删除ECHO关键字验证后激活

在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" 
    } 
}

最新更新