【问题标题】:WindowsServer 2003 cmd check installed rolesWindows Server 2003 cmd 检查安装的角色
【发布时间】:2012-10-15 19:09:33
【问题描述】:

我正在创建一个大型批处理脚本来检查 Windows 2003 服务器上安装的 Windows 功能(组件)。我似乎无法弄清楚如何查询服务器角色并在 cmd shell 中显示角色的所有子功能。这在 Windows Server 2008 中很容易通过简单地使用 servermanager.exe 或 WMI 来完成,但我无法弄清楚在 Windows 2003 中使用什么程序或 cmd。Windows Server 2003 安装了 power shell,但它看起来就像一个美化的 cmd shell在此 Windows 操作系统版本中。有谁知道可以专门在 Windows 2003 机器上使用的类似实用程序或 cmd?感谢您的宝贵时间。

【问题讨论】:

    标签: powershell windows-server-2003 roles


    【解决方案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);
    }
    

    【讨论】:

    • 查看计算机上的远程注册表服务是否已启动并正在运行。
    猜你喜欢
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多