PowerShell V4 and Server 2012 R2 added many new features to existing cmdlets but did not add many new cmdlets. A notable exception is Desired State Configuration (DSC) feature that debuted in PowerShell V4.
DSC is a set of language extensions that enable you to define computer configurations in a declarative fashion then apply that configuration to managed computers. DSC is a tool to provision or manage servers and to ensure those systems stay configured correctly. DSC provides a solution to the problem of configuration drift—computer configurations that change, often incorrectly, over time.
Get more information on DSC in Chapter 13, Using Desired State Configuration.
Two other useful cmdlets included in PowerShell V4 are:
Get-FileHash
: Creates a hash value from a given file or binary value. This is useful for quickly determining whether files have changed or for finding duplicate files (that have different file names)Test-NetConnection
: Diagnoses a network connection and provides helpful troubleshooting information. This cmdlet is described in more detail in Chapter 8, Managing Windows Network Services.
- You use the
Show-Command
to investigate theGet-FileHash
cmdlet:
Show-Command -Name Get-FileHash
Note
Show0-Command
is not available in the Server Core version, as it lacks the graphical user interface.
- In the dialog that pops up, the
Path
tab corresponds to one of three parameter sets for this command. For thePath
tab, enter$Env:windirnotepad.exe
or any other valid file path. - Choose an algorithm like
SHA512
from the drop-down menu. - Click the
Copy
button then paste the command into your PowerShell ISE and press Enter to run it. Note the hash value that is returned. - Use
Show-Command
to investigateTest-NetConnection
:
Show-Command -Name Test-NetConnection
- In the dialog box, the
CommonTCPPort
tab corresponds to the default parameter set, the first of four. ChooseHTTP
from theCommonTCPPort
drop-down, and chooseDetailed
forInformationLevel
. Then clickCopy
, and paste the script into your editor below theShow-Command
line, then close theShow-Command
window. Select this line and press F8 to run this line.
- Repeat your call to
Show-Command -Name Test-NetConnection
. Choose theICMP
tab and enter a valid internet hostname likeWindows.Com
in theComputerName
field, or leave it blank, and chooseDetailed
forInformationLevel
. - Click the
Copy
button then paste the command into your PowerShell ISE below the previous command, then close theShow-Command
window and select the line and press F8 to run it. - Repeat your call to
Show-Command Name Test-NetConnection
. Choose theNetRouteDiagnostics
tab, check the box forDiagnoseRouting
, and clickRun
. - Repeat your call to
Show-Command -Name Test-NetConnection
. Choose theRemotePort
tab, enter443
for thePort
, and chooseDetailed
forInformationLevel
, and clickRun
.
In step 1, you use Show-Command
to provide a graphical interface to explore new commands like Get-FileHash
or new ways to use commands you know. It is the same interface that displays in the Commands
tab in PowerShell ISE, and the interface is programmatically generated from the parameter definitions in the cmdlet or function, so it works with commands you create or install from outside sources.
In steps 2 and 3, choosing the Path
tab corresponds to a parameter set defined in the command; each parameter set may have different required and optional parameters, represented by check boxes, drop-down menus, or text fields. This parameter set requires the Path
and Algorithm
parameters.
In step 4, the Copy
button puts a syntax-correct command on our clipboard, either to be run as is or added to a script and modified. This is a very useful feature for new PowerShell scripters or those working with unfamiliar commands. The result of the command displays in the console, but it could be stored into a variable for comparison with other hash values to look for duplicate or changed files:
In steps 5 and 6, you use Show-Command
to explore the Test-NetConnection
cmdlet. This is a flexible and useful troubleshooting command with four parameter sets to use. First, test the connection to a web host over HTTP port 80
. Note the -InformationLevel Detailed
parameter provides additional troubleshooting information on the connectivity.
In steps 7 and 8, you use the ICMP parameter set with the -InformationLevel Detailed
parameter to ping, using ICMP echo request, a web server. This is different to the earlier steps—here you are just determining whether the target server is responding to echo requests. Some web servers turn off returning of pings, so you may see a server that doesn't respond to a ping but does allow a port 80
HTTP connection.
In step 9, you use the NetRouteDiagnostics
parameter set with the -DiagnoseRouting
parameter, which was introduced in PowerShell 5.1, to get routing information. Here when you click the Run
button, the result displays in the console window.
In step 10, you specify a RemotePort
parameter set with a specified Port
and ComputerName
to test:
Both Server 2012 R2 and PowerShell V4 introduced many new features and added enhancements to existing features. This included the Hyper-V, SmbShare, and BranchCache features, all of which were improved. These features came with PowerShell modules that enable you to leverage these features using PowerShell. Get more information on the modules that support the 2012 R2 features at https://technet.microsoft.com/en-us/library/dn249523.aspx.