Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Instant Windows PowerShell Guide

You're reading from  Instant Windows PowerShell Guide

Product type Book
Published in Nov 2013
Publisher Packt
ISBN-13 9781849686785
Pages 86 pages
Edition 1st Edition
Languages
Author (1):
Harshul Patel Harshul Patel
Profile icon Harshul Patel
Toc

Administer the system (Intermediate)


So far, we have covered changes to the settings in Windows PowerShell Version 3.0 in a general way. Now, let's try to capture how Version 3.0 is useful to the system administrator regarding the ease of working with the console. This recipe consists of multiple subrecipes.

Getting ready

The Add-Computer CMDLET is used for adding a local computer to a domain or workgroup.

How to do it...

Try executing the following code sequence:

  1. The following command statement adds the Member01 server to PSDomain using the PSDomain\PSAdmin credential and restarts the machine once added. It also uses the Force parameter, so it doesn't ask for confirmation.

    PS C:\>Add-Computer -ComputerName Member01 -LocalCredential Member01\Admin01 -DomainName PSDomain -Credential PSDomain\PSAdmin -Restart –Force
    
  2. The following command statement adds the Member01 and Member02 servers to PSDomain using the PSDomain\PSAdmin credential and restarts the machines once added:

    PS C:\>Add-Computer -ComputerName Member01, Member02 -Domain PSDomain -LocalCredential TestDomain\User01 -UnjoinDomainCredential TestDomain\Admin01 -Credential PSDomain\PSAdmin –Restart
    
  3. The following command statement adds the Member01 server to PSDomain using the PSDomain\PSAdmin credential, changes its name to NewMember01, and restarts the machine once added:

    PS C:\>Add-Computer -ComputerName Member01 -Domain PSDomain -NewName NewMember01 -Credential PSDomain\PSAdmin –Restart
    
  4. The following command statement adds the Member02 server to PSDomain using the PSDomain\PSAdmin credential and moves it to the PSOU organizational unit after adding to the domain:

    PS C:\>Add-Computer -ComputerName Member02 -Domain PSDomain –OUPath "OU=PSOU,DC=PSDomain,DC=com" -Credential PSDomain\PSAdmin 
    
  5. The following command statement adds the Member01 server to a workgroup named TestWorkgroup:

    PS C:\>Add-Computer -ComputerName Member01 -WorkgroupName TestWorkgroup
    

How it works…

Given below are the additional parameter names introduced with Add-Computer in Version 3.0:

  • -ComputerName: It specifies the names of the computers, separated by commas, to add them into a domain or workgroup. By default, it takes the local computer name.

  • -Force: It avoids prompt confirmation. By default, it asks for confirmation for each server that we add to the domain or workgroup. We can use the Force parameter name to overcome that.

  • -LocalCredential: It is not a mandatory parameter, but it explicitly provides credentials to connect to the servers specified by the ComputerName parameter. Likewise, the Credential parameter is used to provide valid credentials to join to the domain.

  • -NewName: This parameter provides a new name to a computer in the new domain. It only works when one computer name is supplied to be added or removed.

  • -Restart: It restarts the computers that have been added to the domain or workgroup. Generally, it requires a restart once after joining into a domain and the Restart parameter does this job well.

  • -UnjoinDomainCredential: It passes the credentials of the user account that has permission to unjoin the computer from the current domain. This parameter is useful when we are moving from one domain to another. Likewise, use the Credential and LocalCredential parameters to provide credentials to join the domain and connect to other computers, respectively.

  • -WorkgroupName: This parameter has been introduced with the release of Windows PowerShell 4.0. It specifies the name of the workgroup to which the computers are added. This parameter is only important while adding the computers to a workgroup. Its default value is WORKGROUP.

There's more…

The Remove-Computer CMDLET has the same set of enhancements as Add-Computer. The changes are identical with respect to both the CMDLETs.

Rename-Computer

The Rename-Computer CMDLET is introduced in Windows PowerShell v3.0. It requires the NewName parameter of the server and the DomainCredential parameter to put these changes in effect.

For example:

PS C:\>Rename-Computer -NewName NewMember01 -DomainCredential PSDomain\PSAdmin –Restart

The preceding command statement changes the name of the local computer to NewMember01 using the domain admin credentials PSDomain\PSAdmin. It prompts for the password, changes the name of the local computer, and restarts it to put the changes in effect.

The Rename-Computer CMDLET also supports parameters such as ComputerName, Force, LocalCredential, and Passthru.

Operating the control panel from the console

Two handy CMDLETs introduced with Windows PowerShell version 3.0 are: Get-ControlPanelItem and Show-ControlPanelItem.

PS C :\> Get-ControlPanelItem -Name *Device* | Format-List

The previous command displays all the control panel items containing the Device keyword. Format-List shows information in a list format. The output is shown as follows:

Name          : Device Manager
CanonicalName : Microsoft.DeviceManager
Category      : {All Control Panel Items}
Description   : View and update your hardware's settings and driver software.
Name          : Devices and Printers
CanonicalName : Microsoft.DevicesAndPrinters
Category      : {Hardware and Sound}
Description   : View and manage devices, printers, and print jobs
PS C :\> Get-ControlPanelItem -Name *Printers* | Show-ControlPanelItem

The preceding command statement gets the control panel items that are related to printers and, further, Show-ControlPanelItem opens the Device and Printers window.

Test-Connection

In Version 3, a new parameter name Source is introduced with the Test-Connection CMDLET. If there is a need to check the connectivity of a single machine from multiple locations, the Source parameter is very handy to use.

PS C:\>Test-Connection –Source Member01, Member02 -ComputerName DC01 -Credential PSDomain\PSAdmin

The preceding command statement checks the connectivity for the server DC01 from two servers named Member01 and Member02.

Test-NetConnection

The Test-NetConnection CMDLET is introduced in Windows PowerShell 4.0. It shows the diagnostic information of a connection. It shows various results in the output, for example, the DNS lookup, traceroute information, and so on.

The following are the various parameters that come along with this CMDLET:

  • -CommonTCPPort <String>: It defines the common service TCP port number. The values are: HTTP, PING, RDP, and SMB.

  • -ComputerName <String>: It specifies the DNS name or IP address of the target machine.

  • -Hops <Int32>: It defines the number of hops of traceroute.

  • -InformationLevel <String>: It provides the level of information. The values are: Detailed and Quiet. The Quiet value returns a Boolean value, whereas Detailed gives you in-depth information about a connection.

  • -Port <Int32>: It specifies the TCP port number of a target machine.

  • -TraceRoute: It tests the connectivity of the machine to a remote machine.

For example:

PS C :\> Test-NetConnection –ComputerName PSTest.PSLab.com -Port 8080 -InformationLevel Detailed

The preceding command statement checks the connectivity of PSTest.PSLab.com with respect to the port number 8080 and shows detailed information about the established connection.

You have been reading a chapter from
Instant Windows PowerShell Guide
Published in: Nov 2013 Publisher: Packt ISBN-13: 9781849686785
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 €14.99/month. Cancel anytime}