我正在创建一个大型批处理脚本来检查Windows 2003服务器上已安装的Windows功能(组件)。我似乎无法弄清楚如何查询服务器角色并在cmd shell中显示角色的所有子功能。通过简单地使用servermanager.exe或WMI,这在Windows Server 2008中很容易实现,但是我无法弄清楚Windows 2003中要使用的程序或cmd .Windows Server 2003安装了电源shell,但它看起来像是一个美化的cmd shell在这个Windows操作系统版本中。有没有人知道可以在Windows 2003机器上专门使用的类似实用程序或cmd?谢谢你的时间。
答案 0 :(得分:-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);
}