Cách đơn giản nhất (nó làm việc cho tôi) là:
- mất một máy tính mà vai trò và tính năng cần thiết không được cài đặt
- hãy vào Add Server Roles and Features (trong Server Manager)
- sử dụng thuật sĩ để thêm vai trò cần thiết và các tính năng
- trên màn hình cuối cùng, trước khi nhấn nút "cài đặt", bạn sẽ thấy liên kết "cài đặt cấu hình xuất khẩu"
Export configuration settings
Lưu tệp XML.
Sau khi bạn có tệp XML, bạn có thể sử dụng tập lệnh PowerShell được liệt kê dưới đây để gọi lệnh "Install-WindowsFeature" (Server 2012, 2016).
NOTE1: tập lệnh PowerShell được thiết kế để hoạt động trên Windows Server 2008, 2012 và 2016. Đối với Windows Server 2008, lệnh ghép ngắn là Add-WindowsFeature.
NOTE2: Các kịch bản PowerShell giả định các tập tin XML là trong cùng một thư mục và tên của nó được liệt kê bên trong kịch bản - xin vui lòng xem dòng 3 và 4.
Import-Module ServerManager -ErrorAction Stop
$win2k8xml = '.\features-w2k8.xml'
$win2k12xml = '.\RolesAndFeatures.xml'
$minOSVersion = [version] "6.1.7600" # Windows Server 2008 R2 RTM version
$os = Get-WmiObject Win32_OperatingSystem
$currentVersion = [version]$os.Version
if($currentVersion -lt $minOSVersion)
{
throw "OS version equal or greater than ${minOSVersion} is required to run this script"
}
elseif($currentVersion.ToString().substring(0,3) -eq $minOSVersion.ToString().substring(0,3))
{
If (!(Test-Path $win2k8xml)) {Write-Host "For Windows Server 2008 R2 server make sure that you have Features-W2K8.xml in the current folder" -ForegroundColor Yellow; Pause}
}
elseif($currentVersion -gt $minOSVersion){
If (!(Test-Path $win2k12xml)) {Write-Host "For Windows Server 2012/2016 make sure that you have RolesAndFeatures.xml in the current folder" -ForegroundColor Yellow; Pause}
}
$OSVersionName = (get-itemproperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName
Write-Host "Your OS version is:$OSVersionName" -ForegroundColor Green
$defaultComputerName = $env:computername
$ComputerName = Read-Host "Computername (Press Enter for current computer - $defaultComputerName)"
if ([string]::IsNullOrEmpty($ComputerName))
{
$ComputerName = $defaultComputerName;
}
Write-host "Installation will take place on the following computers: $ComputerName"
function Invoke-WindowsFeatureBatchDeployment {
param (
[parameter(mandatory)]
[string] $ComputerName,
[parameter(mandatory)]
[string] $ConfigurationFilePath
)
# Deploy the features on multiple computers simultaneously.
$jobs = @()
if(Test-Connection -ComputerName $ComputerName -Quiet){
Write-Host "Connection succeeded to: " $ComputerName
if ($currentVersion.ToString().substring(0,3) -eq $minOSVersion.ToString().substring(0,3)) {
$jobs += Start-Job -Command {
#Add-WindowsFeature -ConfigurationFilePath $using:ConfigurationFilePath -ComputerName $using:ComputerName -Restart
$import = Import-Clixml $using:ConfigurationFilePath
$import | Add-WindowsFeature
}
}
elseif ($currentVersion -gt $minOSVersion) {
$jobs += Start-Job -Command {
Install-WindowsFeature -ConfigurationFilePath $using:ConfigurationFilePath -ComputerName $using:ComputerName -Restart
}
}
}
else{
Write-Host "Configuration failed for: "+ $ComputerName + "! Check computer name and execute again"
}
Receive-Job -Job $jobs -Wait | Select-Object Success, RestartNeeded, ExitCode, FeatureResult
}
if ($currentVersion.ToString().substring(0,3) -eq $minOSVersion.ToString().substring(0,3)) {$FilePath = Resolve-Path $win2k8xml}
elseif ($currentVersion -gt $minOSVersion) {$FilePath = Resolve-Path $win2k12xml}
Invoke-WindowsFeatureBatchDeployment $ComputerName $FilePath
Nguồn
2018-01-19 16:34:28
Tôi đang ở Windows Server 2012, nhưng tôi vẫn cần tên chính xác của các tính năng hoặc ít nhất là làm thế nào để có được một danh sách. Bạn có biết làm thế nào điều này được thực hiện? –
bạn đã đọc câu trả lời của tôi chưa ?? Sử dụng get-WindowsFeature PS nó sẽ hiển thị tên: Tên hiển thị Tên ------------ ---- [] Hyper-V Hyper-V [] Ứng dụng phân phối ứng dụng- Máy chủ –
Tôi đã đọc câu trả lời của bạn và tôi mới sử dụng Powershell. –