Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

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"