2012-10-15 59 views
1

我正在創建一個大批量腳本來檢查Windows 2003服務器上已安裝的Windows功能(組件)。我似乎無法弄清楚如何查詢服務器角色並在cmd shell中顯示角色的所有子功能。通過簡單地使用servermanager.exe或WMI,這很容易在Windows Server 2008中完成,但我無法弄清楚在Windows 2003中使用的程序或cmd。Windows Server 2003安裝了電源外殼,但它看起來像是一個美化的cmd外殼在這個Windows操作系統版本。有沒有人知道一個類似的實用程序或cmd可以專門用於Windows 2003的盒子?謝謝你的時間。WindowsServer 2003 cmd檢查已安裝角色

回答

-1

你可以在這裏試試這個功能

function Get-InstalledComponents($computer = '.') { 
    $components_installed = @(); 

    $reg_paths = @('SOFTWARE\Microsoft\Windows\CurrentVersion'` 
      + '\Setup\Oc Manager\Subcomponents'); 
    $reg_paths += @('SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion'` 
      + '\Setup\Oc Manager\Subcomponents'); 

    $hkey = 'LocalMachine'; 
    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hkey, $computer); 
    foreach ($reg_path in $reg_paths) { 
     $reg_key = $reg.OpenSubKey($reg_path); 
     if ($reg_key -eq $null) { 
      continue; 
     } 
     $names = $reg_key.GetValueNames(); 

     foreach ($name in $names) { 
      $value = $reg_key.GetValue($name); 
      if ($value -gt 0) { 
       $components_installed += @($name); 
      } 
     } 
     $reg_key.close(); 
    } 
    $reg.close(); 

    if ($components_installed.count -lt 1) { 
     trap { ; 
     continue } $features = @(get-wmiobject -class 'Win32_ServerFeature' ` 
        -computer $computer -erroraction 'Stop'); 

     foreach ($feature in $features) { 
      $components_installed += @($feature.name); 
     } 
    }  

    return ($components_installed | sort); 
} 
+0

收到錯誤 – cmluciano

+0

查看計算機上遠程註冊表服務已啓動並運行。 – PowerShell