Solved

Add servers to server manager powershell

Posted on 2016-08-19
3
106 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 56

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 78

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
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 Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now