Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Windows Server 2016 Automation with PowerShell Cookbook

You're reading from   Windows Server 2016 Automation with PowerShell Cookbook Powerful ways to automate and manage Windows administrative tasks

Arrow left icon
Product type Paperback
Published in Sep 2017
Publisher
ISBN-13 9781787122048
Length 660 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Thomas Lee Thomas Lee
Author Profile Icon Thomas Lee
Thomas Lee
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. What's New in PowerShell and Windows Server FREE CHAPTER 2. Implementing Nano Server 3. Managing Windows Updates 4. Managing Printers 5. Managing Server Backup 6. Managing Performance 7. Troubleshooting Windows Server 2016 8. Managing Windows Networking Services 9. Managing Network Shares 10. Managing Internet Information Server 11. Managing Hyper-V 12. Managing Azure 13. Using Desired State Configuration

Exploring Remote Server Administration Tools (RSAT)

Remote Server Administration Tools (RSAT) are tools available on both servers and client systems to manage server services. RSAT tools are available in Windows desktop and server versions. Most of the RSAT tools are not installed by default but are easily added.

RSAT includes GUI tools, like Microsoft Management Console (MMC) and MMC snap-ins (for example the DNS or DHCP MMC snap-ins) as well as command-line tools and additional PowerShell modules. You have the option of installing the Windows feature including the tools (most useful on a server), or just the tools to manage the feature (most useful on a workstation).

The recipe that follows is run from DC1, a Windows Server 2016 with Desktop Experience installation. If you try to use Server Core for this recipe, note that Out-GridView, for example in step 3, is not available in the Server Core version, as it lacks the graphical user interface. For Server Core installations, use Format-Table instead.)

How to do it...

  1. You use the Get-Command, and Tee-Object cmdlets to retrieve both the collection of PowerShell commands and the number of cmdlets into PowerShellvariables before installing the RSAT:
      $CountOfCommandsBeforeRSAT = Get-Command |
          Tee-Object -Variable 'CommandsBeforeRSAT' |
              Measure-Object
      '{0} commands' -f $CountOfCommandsBeforeRSAT.count
  
  1. Examine the objects returned by Get-Command:
      $CommandsBeforeRSAT | Get-Member |
       Select-Object -ExpandProperty TypeName -Unique
  
  1. View commands in Out-GridView:
      $CommandsBeforeRSAT |
         Select-Object -Property Name, Source, CommandType |
            Sort-Object -Property Source, Name |
               Out-GridView
Out-GridView is not available in the Server Core version, as it lacks the graphical user interface. For Server Core installations, use Format-Table instead.
  1. Store the collection of PowerShell modules and a count into variables as well:
      $CountOfModulesBeforeRSAT = Get-Module -ListAvailable |
         Tee-Object -Variable 'ModulesBeforeRSAT' |
             Measure-Object 
                '{0} commands' -f $CountOfModulesBeforeRSAT.count
  1. View modules in Out-GridView:
     $ModulesBeforeRSAT |
          Select-Object -Property Name -Unique |
             Sort-Object -Property Name |
                Out-GridView
  
  1. Review the RSAT Windows Features available and their installation status:
       Get-WindowsFeature -Name RSAT*
Get-WindowsFeature only works on Windows Server operating systems.
  1. Install RSAT with sub features and management tools:
      Install-WindowsFeature -Name RSAT -IncludeAllSubFeature `
-
IncludeManagementTools
  1. Now that RSAT features are installed, see what commands are available:
      $CountOfCommandsAfterRSAT = Get-Command | 
         Tee-Object -Variable 'CommandsAfterRSAT' |
             Measure-Object 
       '{0} commands' -f $CountOfCommandsAfterRSAT.count
  1. View commands in Out-GridView:
     $CommandsAfterRSAT |
        Select-Object -Property Name, Source, CommandType |
           Sort-Object -Property Source, Name |
              Out-GridView
  1. Now check how many modules are available:
      $CountOfModulesAfterRSAT = Get-Module -ListAvailable |
         Tee-Object -Variable 'ModulesAfterRSAT' |
             Measure-Object
      '{0} commands' -f $CountOfModulesAfterRSAT.count
  1. View modules in Out-GridView:
      $ModulesAfterRSAT | Select-Object -Property Name -Unique |
Sort-Object -Property Name |
Out-GridView
  1. Store the list of commands into an XML file for later research:
      $CommandsAfterRSAT |
Export-Clixml `
-Path $env:HOMEPATH\Documents\WS2016Commands.XML"

How it works...

In step 1, you use Get-Command to enumerate all the commands available in PowerShell. This includes functions and aliases. It is useful to store the result of such commands into a variable, $CommandsBeforeRSAT in this case, so you are able to investigate the commands without making the request again. Using Tee-Object, you store the array of commands in that variable while continuing to use the pipeline to Measure-Object to store the count of commands, then display the result using the PowerShell string formatting function: '{0} commands' -f $CountOfCommandsBeforeRSAT

In step 2, you pipe the $CommandsBeforeRSAT variable to Get-Member to examine the TypeName of the objects returned, as shown in the following screenshot:

As you see, these commands are objects of the AliasInfo, FunctionInfo, and CmdletInfo types in the System.Management.Automation namespace (plus a FilterInfo type, which provides information about a filter that is stored in the session state.) PowerShell commands returned by Get-Command include aliases, functions, and cmdlets.

In step 3, you use Select-Object to show the useful properties, and pipe that to a Sort-Object, then pipe to Out-GridView to search and filter the PowerShell commands, as you see in the following screenshot:

In step 4, you use Get-Module just like Get-Command, but use the -ListAvailable parameter to see all the installed modules, not just those loaded into the current session. Again you use Tee-Object to store the array of modules into a variable, $ModulesBeforeRSAT, while passing the result down the pipeline to Measure-Object to calculate the count which you then display.

In step 5, you pipe the variable to a Select-Object for the interesting columns, Sort-Object, then pipe that to Out-GridView again to review the available modules as shown here:

In step 6, you view the RSAT features available in your server with Get-WindowsFeature -Name RSAT*, as shown in the following screenshot:

Get-WindowsFeature presents an information dense tree view of the RSAT tools available. Note the many sub-features under Remote Server Admin Tools and under Role Administration Tools. Each feature may be installed individually by name, or all features installed with one command as in this example.

In step 7, install all the RSAT features with the -IncludeAllSubFeature and
-IncludeManagementTools parameters. You may limit what is installed by changing the first parameter to a comma separated list of desired feature names.

In steps 8-11, once the RSAT features are installed, repeat the Get-Command and Get-Modules code to see all the additional cmdlets and modules.

In step 12 you use Export-CliXML to store the array to an XML file. If you want to compare what is available in different OS and PowerShell versions, you use the array of objects saved to this file and compare it with an XML file generated under some other PowerShell or Windows versions.

There's more...

You have been reading a chapter from
Windows Server 2016 Automation with PowerShell Cookbook - Second Edition
Published in: Sep 2017
Publisher:
ISBN-13: 9781787122048
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image