PowerShell/Additional Topics

This lesson introduces additional PowerShell topics, including custom objects, web requests, email, and Active Directory users and groups.

Objectives and Skills
After completing this lesson, you will be able to:
 * Describe basic PowerShell object concepts.
 * Create PowerShell scripts to work with .NET library objects.
 * Create PowerShell scripts to work with COM objects.
 * Create PowerShell scripts to retrieve web pages.
 * Create PowerShell scripts to send email.
 * Create PowerShell scripts to manage Active Directory users and groups.

Readings

 * 1)  Object (computer science)
 * 2)  Hypertext Transfer Protocol
 * 3)  Simple Mail Transfer Protocol
 * 4)  Active Directory
 * 5) BonusBits: Mastering PowerShell Chapter 6 - Using Objects

Multimedia

 * 1) YouTube: PowerShell Fundamentals - Working with Objects
 * 2) YouTube: PowerShell Filtering Functions and Custom Objects
 * 3) YouTube: Manipulate Excel Workbooks and Worksheets with Powershell
 * 4) YouTube: Logging Into webpage with Invoke-WebRequest
 * 5) YouTube: Send an Email From PowerShell
 * 6) YouTube: User Account Mgmt Using PowerShell

New-Object
The New-Object cmdlet creates an instance of a .NET Framework or COM object.

PowerShell custom objects are created using the .NET PSObject class.

Microsoft Excel is accessed as a COM object using Excel.Application.

Invoke-WebRequest
The Invoke-WebRequest cmdlet sends HTTP, HTTPS, FTP, and FILE requests to a web page or web service.

Send-MailMessage
The Send-MailMessage cmdlet sends an email message.

Import-Module
The Import-Module cmdlet adds one or more modules to the current session.

New-ADUser
The New-ADUser cmdlet creates a new Active Directory user.

Get-ADUser
The Get-ADUser cmdlet gets a user object or performs a search to retrieve multiple user objects.

Set-ADUser
The Set-ADUser cmdlet modifies the properties of an Active Directory user.

Remove-ADUser
The Remove-ADUser cmdlet removes an Active Directory user.

New-ADGroup
The New-ADGroup cmdlet creates a new Active Directory group object.

Remove-ADGroup
The Remove-ADGroup cmdlet removes an Active Directory group object.

Add-ADGroupMember
The Add-ADGroupMember cmdlet adds one or more users, groups, service accounts, or computers as new members of an Active Directory group.

Remove-ADGroupMember
The Remove-ADGroupMember cmdlet removes one or more users, groups, service accounts, or computers from an Active Directory group.

Activities

 * 1) Review Microsoft TechNet: Use PowerShell for Network Host and Port Discovery Sweeps. Use a for loop and the System.Net.NetworkInformation.Ping object to loop through your entire subnet and create an array of IP addresses on the subnet that respond to ping. Use Arp to identify hosts on the network that responded to the Arp request but blocked a ping response and add those hosts to the array. Then display the array.
 * 2) Review WindowsITPro: PowerShell Basics: Custom Objects. Create a script that uses Get-WmiObject to retrieve multiple computer properties and add those properties to a custom PSObject. Create an array of custom PSObject objects, with a separate object for each of several computers on the network. Pipe the array through Out-GridView to display the combined results.
 * 3) Review Learn PowerShell: PowerShell and Excel. Create a script that uses the Excel.Application COM object and nested for loops to generate a 10 x 10 multiplication table in the first worksheet in a new Excel workbook.
 * 4) Review Microsoft TechNet: Use PowerShell to Download Web Page Links from a Blog. Create a script that uses Invoke-WebRequest to download all links from https://en.wikiversity.org/wiki/Windows_PowerShell . Create an array of the links on the page. Use a recursive function so that the script also lists the links of any subpages of the page. Display the results using Out-GridView.
 * 5) Create a script to email all warning and error events from the previous 24 hours as a formatted list. Use the computer name in the from address, and include the current date in the subject. Use Task Scheduler to schedule the script to run daily at a given time, such as 6 a.m.
 * 6) Review Microsoft MSDN: Active Directory Module for Windows PowerShell – Quick start guide. Create a text file that lists 10 new users and the department they will work for in username, department format. Use Get-Content to read the file, New-ADUser to add the user, and Add-ADGroupMember to add the user to their department. Departments can be created manually or using New-ADGroup. Open Active Directory Users and Computers to confirm the users were created and added to their respective groups.

Lesson Summary

 * An object is a location in memory having a value and possibly referenced by an identifier.
 * The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems, and is the foundation of data communication for the World Wide Web.
 * HTTP functions as a request-response protocol in the client-server computing model. The client submits an HTTP request message to the server. The server, which provides resources such as HTML files and other content, or performs other functions on behalf of the client, returns a response message to the client. The response contains completion status information about the request and may also contain requested content in its message body.
 * Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (e-mail) transmission.
 * SMTP by default uses TCP port 25. The protocol for mail submission is the same, but uses port 587.
 * While electronic mail servers and other mail transfer agents use SMTP to send and receive mail messages, user-level client mail applications typically use SMTP only for sending messages to a mail server for relaying. For receiving messages, client applications usually use either POP3 or IMAP.
 * Active Directory (AD) is a directory service that Microsoft developed for Windows domain networks and is included in most Windows Server operating systems as a set of processes and services.
 * An Active Directory domain controller authenticates and authorizes all users and computers in a Windows domain type network.
 * An Active Directory structure is an arrangement of information about objects. The objects fall into two broad categories: resources (e.g., printers) and security principals (user or computer accounts and groups).
 * The New-Object cmdlet creates an instance of a .NET Framework or COM object.
 * PowerShell custom objects are created using the .NET PSObject class.
 * Microsoft Excel is accessed as a COM object using Excel.Application.
 * The Invoke-WebRequest cmdlet sends HTTP, HTTPS, FTP, and FILE requests to a web page or web service.
 * The Send-MailMessage cmdlet sends an email message.
 * The Import-Module cmdlet adds one or more modules to the current session.
 * The New-ADUser cmdlet creates a new Active Directory user.
 * The Get-ADUser cmdlet gets a user object or performs a search to retrieve multiple user objects.
 * The Set-ADUser cmdlet modifies the properties of an Active Directory user.
 * The Remove-ADUser cmdlet removes an Active Directory user.
 * The New-ADGroup cmdlet creates a new Active Directory group object.
 * The Remove-ADGroup cmdlet removes an Active Directory group object.
 * The Add-ADGroupMember cmdlet adds one or more users, groups, service accounts, or computers as new members of an Active Directory group.
 * The Remove-ADGroupMember cmdlet removes one or more users, groups, service accounts, or computers from an Active Directory group.

Key Terms

 * Component Object Model (COM)
 * A binary-interface standard for software components introduced by Microsoft in 1993, which is used to enable inter-process communication and dynamic object creation in a large range of programming languages.


 * HTML (HyperText Markup Language)
 * The standard markup language used to create web pages.


 * Post Office Protocol (POP)
 * An application-layer Internet standard protocol used by local e-mail clients to retrieve e-mail from a remote server over a TCP/IP connection.


 * Internet Message Access Protocol (IMAP)
 * A protocol for e-mail retrieval and storage which specifically allows multiple clients simultaneously connected to the same mailbox.

Assessments

 * Flashcards: Quizlet: Windows PowerShell - Additional Topics
 * Quiz: Quizlet: Windows PowerShell - Additional Topics