當您在 Windows 7 型電腦上開啟 VAMT 2.0 中的清單時,出現「已經新增相同金鑰的專案」錯誤
本文可協助修正錯誤 () 當您在大量啟用管理工具中開啟清單 (VAMT) 2.0 時,就會發生此專案。
原始產品版本: Windows 7 Service Pack 1
原始 KB 編號: 2383895
徵狀
當您在 .cil
Windows 7 電腦上開啟 VAMT 2.0 中的清單 () 時,可能會收到下列錯誤訊息:
已新增具有相同金鑰的專案。
原因
如果電腦中有多個網路介面卡,而且這些網路介面卡具有相同的 MAC 位址,可能會發生此問題。 例如,如果虛擬機器有兩個網路介面卡,並將這些網路介面卡設定為具有相同的 MAC 位址,便會發生此問題。
在此情況下,如果您開啟 CIL 檔案,您會看到類似下列的專案:
NetworkName = "
contoso.com
" Id = "e3f3f83c-f050-4d81-9117-xx" >
<MacAddresses>
<MacAddress>00:11:11: CF: FC: xx</MacAddress>
<MacAddress>00:11:11: CF: FC: xx</MacAddress>
</MacAddresses>
解決方案
若要解決此問題,請手動刪除 CIL 中的重複專案,或若要自動化此程式,請使用下列原始程式碼建立 PowerShell 腳本,以進行自動處理。
param($inputFilePath, $vamtDirPath)
$cilFilePath = Resolve-Path $inputFilePath;
if (!$cilFilePath)
{
Write-Error "Expected input file name of target CIL";
exit 1;
}
if ($vamtDirPath)
{
$vamtDirPath = Resolve-Path $vamtDirPath;
}
else
{
$prograPath = [environment]::GetEnvironmentVariable("ProgramFiles(x86)");
if (!$prograPath -or $prograPath -eq "")
{
$prograPath = [environment]::GetEnvironmentVariable("ProgramFiles");
}
$vamtDirPath = $prograPath + "\VAMT 2.0"
}
try
{
$assembly = [System.Reflection.Assembly]::LoadFile($vamtDirPath + "\Vamtrt.dll");
}
catch
{
Write-Error "Error while attempting to load VAMT assembly. Provide the correct path to your VAMT installation if VAMT is not installed to the default directory.";
exit 1;
}
$fileSerializer = new-object Microsoft.SoftwareLicensing.Vamt.FileSerializer($cilFilePath);
$softwareLicensingData = $fileSerializer.Deserialize();
for ($i = 0; $i -lt $softwareLicensingData.Machines.Length; $i++)
{
$machine = $softwareLicensingData.Machines[$i];
if ($machine.MacAddresses.Count -gt 0)
{
$distinctMacAddrs = new-object System.Collections.ObjectModel.Collection[string];
foreach ($mac in $machine.MacAddresses)
{
if (!$distinctMacAddrs.Contains($mac))
{
$distinctMacAddrs.Add($mac);
}
}
$machine.MacAddresses.Clear();
foreach ($distinctMac in $distinctMacAddrs)
{
$machine.MacAddresses.Add($distinctMac);
}
}
}
$fileSerializer.Serialize($softwareLicensingData);
然後,在 Windows 7 電腦上執行下列步驟:
將儲存的 CIL 檔複製到 c:\script。 例如,c:\script\saved.cil
將包含的原始程式碼從此 KB 文章複製到剪貼簿
按一下 [開始]、[所有程式、附件、Windows PowerShell],"Windows PowerShell ise"
在 [Windows PowerShell] 的 [Untitled1.ps1] 視窗中按一下
在本文中貼上腳本的內容
按一下 [檔案]、[另存新檔] c:\script\ScrubCil.ps1
按一下 [> 所有程式 > 附件 > Windows PowerShell],以滑鼠右鍵按一下 [Windows PowerShell],然後選擇 [以系統管理員身分執行]。
在 PowerShell 的提示字元類型上,下列命令
cd\script set-executionpolicy unrestricted .\ScrubCil.ps1 saved.cil