Step-by-Step: Extending Server Manager in Windows Server 2012 and 2012 R2 with custom PowerShell tools

Server Manager in Windows Server 2012 and 2012 R2 has been completely retooled into a powerful multi-server management GUI tool that provides remote management of Windows servers and a health-check dashboard snapshot view to quickly verify that “all-is-well” across Windows servers within your datacenter. 

image
Server Manager in Windows Server 2012 and 2012 R2

But, the built-in management capabilities of Server Manager have also been built on an extensible framework.  As a result, you can easily integrate your own management tools and PowerShell scripts into the core functionality of Server Manager to create your own customized management launchpad.

In this article, I’ll step through the task of extending Server Manager with additional management scripts.  Along the way, we’ll create a simple, but useful PowerShell management script that inventories the UNC shared folders paths that exist across all managed servers on a network.

Where does Server Manager store its Managed Server List?

When creating a new management tool that integrates with Server Manager, I typically want to this management tool to reference the list of servers that I’ve added into Server Manager as managed servers.  This is the list of Servers that appears on the All Servers page in Server Manager.

image
Server Manager – List of All Managed Servers

Tip: You can add new servers to be managed via Server Manager by selecting Manage | Add Servers from the top menu bar in Server Manager.

By leveraging the existing list of All Servers in Server Manager for new custom tools and scripts, these new tools can automatically reference all servers that have been added into Server Manager, without the need to manage additional lists of managed servers on a tool-by-tool basis.

Server Manager stores the list of all servers being managed in an XML file in the following folder path:

%APPDATA%\Microsoft\Windows\ServerManager\ServerList.XML

image
Server Manager – ServerList.XML stores list of Managed Servers

We can easily leverage ServerList.XML as the starting point for providing a list of servers for our custom script with just a few lines of PowerShell code that can read in this list of servers as initial input.

$ServerManagerXML = "$env:APPDATA\Microsoft\Windows\ServerManager\ServerList.xml"

$file = Get-Item $ServerManagerXML

$xml = [xml] (Get-Content $file)

$xml.ServerList.ServerInfo.Name

The short PowerShell code snippet above uses the Get-Content cmdlet to read ServerList.XML and returns a list of server names for each managed server.  With this snippet, we now have a list of managed servers that we can pipe into a PowerShell code block for performing the particular task on which our new custom tool is focused.

OK … Now, let’s do something!

In the following script example, we’ll leverage the Get-SmbShare cmdlet inside a code block that loops through each of our managed servers and returns a list of all UNC paths that are being shared across our network.  While Server Manager can display a list of defined share names on the File and Storage Services page, it doesn’t display the full UNC paths for each shared folder in a format that is easy to copy and paste, and it also doesn’t display hidden shares ( ie., share names defined with a $ at the end ). 

The simple code block below will return a list of all shares across our list of managed servers in a format that we can easily copy and paste when working with these folders.  We’ll also leverage the Out-GridView cmdlet to return the output in a GUI window that we’ll be able to integrate nicely with Server Manager.

$ServerManagerXML = "$env:APPDATA\Microsoft\Windows\ServerManager\ServerList.xml"

$file = Get-Item $ServerManagerXML

$xml = [xml] (Get-Content $file)

$xml.ServerList.ServerInfo.Name |

    % {
$session = New-CimSession -ComputerName $_
Get-SmbShare -CimSession $session
} |

    Select-Object -Property @{Name="UNCPath";Expression={"\\"+$_.PSComputerName+"\"+$_.Name}}, Description |

    Out-GridView -Title "UNC Paths" -Wait

After running this script, you’ll see the following scrollable list of UNC paths for all existing shared folders across all managed servers. 

image
Out-GridView window listing all UNC paths across managed servers

Inside the Out-GridView window, you can select a particular row and press Ctrl-C to copy that row to your clipboard  In addition, you can sort, filter, and change columns in the displayed output by clicking on the filter control and/or column headings located at the top of the Out-GridView window.

Tip: If you want to leverage an Out-GridView window to pass through selected rows into another code block to perform a task on the selected rows, you can change the –Wait parameter in the Out-GridView cmdlet to –PassThru.  This will allow you to pipe the selected output from Out-GridView into another code block that performs additional processing on the selected output. Very cool!

Ready to integrate into Server Manager!

Now that we have developed and tested our script, we can integrate this new tool into Server Manager so that we can quickly find it when needed.  The Tools menu in Server Manager provides an easy method for launching new tools from within the Server Manager UI.

image
Server Manager – Tools menu

When displaying the Tools menu, Server Manager looks in the following folder for existing shortcuts and subfolders to list on the Tools menu:

%PROGRAMDATA%\Microsoft\Windows\Start Menu\Programs\Administrative Tools

To include our new tool on this menu, we simply need to save our script to a folder that we’ll be able to access and then add a new shortcut in this folder.

  1. Save the PowerShell script defined above as a file named ShowUNCPaths.ps1 in a folder to which you have access, such as C:\PSScripts
     
  2. Create a new shortcut in the Administrative Tools folder path listed above that runs the following command line:
     
    %windir%\system32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden C:\PSSCripts\ShowUNCPaths.ps1

Tip: In addition to adding new shortcuts to the Administrative Tools folder for appearing on the Tools menu in Server Manager, you can also re-organize the existing shortcuts in this folder into sub-folders and dramatically reduce the length of the Tools menu.  This can make it much easier to quickly locate management tools by grouping them into common sub-folders on the Tools menu.

Once you’ve completed these two final steps, the Show UNC Paths script should appear as a new management tool on the Tools menu in Server Manager!

Share Your Tool Ideas!

Do you have a cool idea for a custom management tool that can be integrated into Server Manager? Share your ideas and we may write them up in a future article!

Other resources in which you may be interested …