首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WindowsServer 2003命令检查已安装的角色

WindowsServer 2003命令检查已安装的角色
EN

Stack Overflow用户
提问于 2012-10-16 03:09:34
回答 1查看 4.6K关注 0票数 1

我正在创建一个大型批处理脚本来检查windows 2003服务器上已安装的Windows功能(组件)。我似乎想不出如何查询服务器角色并在cmd shell中显示该角色的所有子功能。这在Windows Server2008中很容易做到,只需使用servermanager.exe或WMI,但我不知道在Windows2003中使用什么程序或命令。Windows Server2003已经安装了power shell,但在这个Windows OS版本中,它看起来就像是一个美化的cmd shell。有没有人知道可以专门在Windows2003机器上使用的类似的实用程序或命令?耽误您时间,实在对不起。

EN

回答 1

Stack Overflow用户

发布于 2012-11-12 20:11:19

您可以尝试此函数

代码语言:javascript
复制
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);
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12902380

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档