Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Add servers to server manager powershell

Posted on 2016-08-19
3
238 Views
Last Modified: 2016-08-20
Hi Experts,

can someone help understand how i would add multiple servers?  The below article describes how to add a single server to server manager using PS

https://blogs.technet.microsoft.com/keithmayer/2013/08/06/step-by-step-using-powershell-to-add-servers-to-server-manager-in-windows-server-2012/
0
Comment
Question by:cmatchett
3 Comments
 
LVL 57

Expert Comment

by:Cliff Galiher
ID: 41763190
Just rerun the command for each server you want to add.  Or write a for-loop (Powershell supports this) and feed it a list of machines...from a text file...hand entered, etc...
0
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 500 total points
ID: 41763203
Try this
<#
.Synopsis
Short description
.DESCRIPTION
Add Servers to Server Manager in Windows Server 2012
.EXAMPLE
add-server c:\serverlist.txt
.NOTES
General notes
.FUNCTIONALITY
The functionality that best describes this cmdlet
#>
function Add-ToServerManager
{
[CmdletBinding()]
Param
(
# Servernames to add to Server Manager
[Parameter(Mandatory=$true,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            Position=0)
            ]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[string]$Servername
)
try {
$newserver = @($xml.ServerList.ServerInfo)[0].clone()
$newserver.name = $Servername
$newserver.lastUpdateTime = '0001-01-01T00:00:00'
$newserver.status = '2'
$xml.ServerList.AppendChild($newserver)
$xml.Save($file.FullName)
}
catch {
write-output('Error in Adding server {0} to serverlist xml' -f $Servername)
}
}        

Function Add-Server
{
[CmdletBinding()]
Param
(
# Path to text file that has list of Server Names
[Parameter(Mandatory=$true,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            Position=0)
            ]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[string]$serverlist
)


if (!(test-path $serverlist)){
   write-output ('{0} does not exist' -f $serverlist)
   }
else {
    $servers = get-content -path $serverlist
    get-process ServerManager | stop-process –force
    $file = get-item “$env:USERPROFILE\AppData\Roaming\Microsoft\Windows\ ServerManager\ServerList.xml”
    copy-item –path $file –destination $file-backup –force
    foreach($server in $servers){ add-toservermanager($server)}
    $xml.Save($file.FullName)
    start-process –filepath $env:SystemRoot\System32\ServerManager.exe –WindowStyle Maximized
    }
}

Open in new window

0
 

Author Closing Comment

by:cmatchett
ID: 41763775
pointed in me in right direction
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Set OWA language and time zone in Exchange for individuals, all users or per database.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
In this Micro Tutorial viewers will learn how to use Windows Server Backup to create full image of their system. Tutorial shows how to install Windows Server Backup Feature on Windows 2012R2 and how to configure scheduled Bare Metal Recovery backup.…
In this Micro Tutorial viewers will learn how they can get their files copied out from their unbootable system without need to use recovery services. As an example non-bootable Windows 2012R2 installation is used which has boot problems.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question