我正在创建一个大型批处理脚本来检查windows 2003服务器上已安装的Windows功能(组件)。我似乎想不出如何查询服务器角色并在cmd shell中显示该角色的所有子功能。这在Windows Server2008中很容易做到,只需使用servermanager.exe或WMI,但我不知道在Windows2003中使用什么程序或命令。Windows Server2003已经安装了power shell,但在这个Windows OS版本中,它看起来就像是一个美化的cmd shell。有没有人知道可以专门在Windows2003机器上使用的类似的实用程序或命令?耽误您时间,实在对不起。
发布于 2012-11-12 20:11:19
您可以尝试此函数
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);
}https://stackoverflow.com/questions/12902380
复制相似问题