You are previewing PowerShell 3.0 Advanced Administration Handbook.
O'Reilly logo
PowerShell 3.0 Advanced Administration Handbook

Book Description

A fastpaced PowerShell guide with realworld scenarios and detailed solutions

  • Discover and understand the concept of Windows PowerShell 3.0

  • Learn the advanced topics and techniques for a professional PowerShell scripting

  • Explore the secret of building custom PowerShell snap-ins and modules

  • Take advantage of PowerShell integration capabilities with other technologies for better administration skills

  • Step-by-step guide rich with real-world script examples, screenshots, and best practices

  • In Detail

    Technology’s growing rhythm is running faster than before, and business needs are getting more complex every day. So, it is time to learn something new to help conquer the challenge. With PowerShell in your toolbox, you can easily perform many tasks with less time, effort, and cost. PowerShell is a helpful scripting technology that enables the automation of system management tasks and the creation of system management tools.

    "PowerShell 3.0 Advanced Administration Handbook" comes with a set of real-world scenarios and detailed scripts that will help you get started with PowerShell, learn what PowerShell is, how to write the syntax, and build your scripts, and how to use and integrate PowerShell with different technologies, products, and tools.

    This handbook starts with the essential topics of PowerShell, then introduces the new features in PowerShell 3.0. The book then goes through building PowerShell scripts, function, and developing extensions like snap-ins and modules, and continues with detailed examples showing the usage of PowerShell with different technologies and products to give you an idea of PowerShell usage in the real world.

    Table of Contents

    1. PowerShell 3.0 Advanced Administration Handbook
      1. Table of Contents
      2. PowerShell 3.0 Advanced Administration Handbook
      3. Credits
      4. About the Authors
      5. Acknowledgement
      6. Acknowledgement
      7. About the Reviewers
      8. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
          3. Instant Updates on New Packt Books
      9. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      10. 1. Getting Started with PowerShell
        1. Working with pipelines
          1. Viewing the object structure
          2. Using format cmdlets to change the output view
          3. Using cmdlets to redirect data
        2. Variables and objects
          1. Using variables to store objects
          2. Getting CIM objects
            1. Listing CIM classes
            2. Displaying details of the CIM classes
          3. Creating .NET and COM objects
        3. Looping and flow control
          1. Comparison and logical operators
          2. Conditional statements
          3. Using switches to manage large conditional statements
          4. Repeat operations with loops
            1. The for statement
            2. The foreach statement
            3. Nested loops
        4. Lists, arrays, and hash tables
        5. Operating script block
          1. Defining script blocks
          2. Passing parameters and returning values
        6. Functions
        7. Scripts
          1. Creating scripts
            1. Invoking scripts
            2. Passing parameters
            3. Return values
          2. Developing and maintaining script libraries
        8. Discovering what's new in Windows PowerShell 3.0
        9. Windows PowerShell Web Access (PSWA)
          1. How PSWA works
          2. Installing and configuring Windows PowerShell Web Access
            1. Step 1 – installing the Windows PowerShell Web Access Windows feature
            2. Step 2 – configuring Windows PowerShell Web Access Gateway
            3. Step 3 – configuring the PowerShell Web Access authorization rules
              1. Signing in to PowerShell Web Access
        10. Auto-loading of modules
        11. Online and updatable Help
        12. Scheduled jobs
        13. The Show-Command cmdlet
        14. Integrated Scripting Environment (ISE)
          1. IntelliSense
          2. Script snippets
            1. How to use snippets
            2. How to create/add new snippets
          3. Add-on tools
          4. Autosave and restart manager
        15. PowerShell remoting
          1. Disconnected session
          2. Remoting on a public network
          3. The custom session configuration file
        16. Windows PowerShell Workflow (PSW)
          1. Creating a workflow using PowerShell
          2. Controlling PowerShell Workflow execution
        17. Summary
      11. 2. Developing Snap-ins for PowerShell
        1. Creating a PowerShell snap-in
        2. Writing a PowerShell snap-in
          1. Creating a new class library project
          2. Creating a PowerShell installer class
          3. Creating a class file to include several PowerShell cmdlets
            1. Declaring cmdlet parameters
            2. Declaring parameter sets
            3. Validating the parameter inputs
              1. Validating the argument set
              2. Validating the argument range
              3. Validating the argument pattern
              4. Validating the argument length
              5. Validating the argument count
            4. Overriding methods
        3. Registering and removing a PowerShell snap-in
          1. Registering and removing snap-in in PowerShell 1.0
          2. Registering and removing a snap-in in PowerShell 3.0
        4. Listing and executing cmdlets in a PowerShell snap-in
        5. Debugging a PowerShell snap-in
        6. Summary
      12. 3. Using PowerShell Remoting
        1. An overview of PowerShell remoting
        2. Enabling/disabling remoting
          1. Operating PowerShell in a no-domain environment
            1. Setting the network location to Private
            2. Enable PSRemoting
            3. Configuring WSMan trusted hosts
          2. Configuring PowerShell remoting on a domain using Group Policy
            1. Allowing remote server management through WinRM
            2. Allowing Windows Remote Management through Windows Firewall
            3. Turning on Service Windows Remote Management (WS-Management)
            4. Doing a Group Policy Update
          3. Disabling remoting
        3. Executing the remoting commands
          1. Running ScriptBlock on a remote computer
          2. Creating a persistent session with Invoke-Command
          3. Running remote commands as a job
          4. Specifying credentials required for remoting
        4. Entering an interactive remoting session
          1. Exiting an interactive session
          2. Using a persistent session with interactive remoting
          3. Starting interactive remoting with an existing session
          4. Disconnecting and reconnecting sessions
        5. Saving a remote session to a disk
          1. Exporting a remote session to a module on a disk
          2. Importing a module saved on a disk
          3. Limitations of Export-PSSession
        6. Using session configurations
          1. Creating a new session configuration
          2. Listing available session configurations
          3. Custom permissions and PS session configurations
          4. Invoking a custom session configuration
          5. Disabling a session configuration
          6. Deleting a session configuration
        7. Summary
      13. 4. Extending Windows PowerShell
        1. Introduction to Windows PowerShell modules
        2. PowerShell module types
          1. Script modules
          2. Binary modules
          3. Manifest modules
          4. Dynamic modules
        3. The PSModulePath environment variable
          1. Viewing the PSModulePath variable
          2. Adding locations to the PSModulePath variable
        4. Importing PowerShell modules
        5. Removing PowerShell modules
        6. Reloading PowerShell modules
        7. Writing a PowerShell module
          1. Creating script modules
          2. Binary modules
          3. Manifest modules
          4. Dynamic modules
        8. Storing modules on a disk
        9. Working with multiple versions of modules
        10. Checking PowerShell module dependencies
        11. Signing PowerShell modules
          1. Execution policies
          2. Changing the execution policy
          3. Script signing background
          4. Setting up a self-signed certificate
          5. Signing a module
        12. Summary
      14. 5. Managing Core Infrastructure with PowerShell
        1. Preparing the operating system for first time use
          1. Task 1 – changing the computer name
          2. Task 2 – changing the time zone settings
          3. Task 3 – setting the Network Interface Card (NIC) configuration
          4. Task 4 – managing Windows Server roles and features
            1. Example 1
            2. Example 2
        2. Deploying the Active Directory Domain Services (ADDS) role
          1. Scenario 1 – installing a new Active Directory Forest
          2. Scenario 2 – installing a new domain in an existing forest
          3. Scenario 3 – installing a new domain controller in an existing domain
        3. Managing and configuring the Domain Name System (DNS) role
          1. Task 1 – configuring DNS server resource records
          2. Task 2 – creating primary forward and reverse lookup zones
          3. Task 3 – adding a DNS server forwarder
          4. Task 4 – exporting DNS server zones
        4. Deploying and configuring the Dynamic Host Configuration Protocol (DHCP) role
          1. Task 1 – installing the DHCP server role
          2. Task 2 – setting up the DHCP server scope
          3. Task 3 – configuring DHCP scope options
          4. Task 4 – configuring DHCP scope exclusion
          5. Task 5 – configuring DHCP scope reservations
          6. Task 6 – authorizing the DHCP server in Active Directory
        5. Managing Windows Firewall
          1. Task 1 – enabling or disabling Windows Firewall profiles
          2. Task 2 – creating Windows Firewall rules
            1. Example 1
            2. Example 2
        6. Using the Best Practice Analyzer (BPA)
          1. Task 1 – displaying the list of best practice models
          2. Task 2 – invoking a best practice model
          3. Task 3 – showing the best practice model result
        7. Summary
      15. 6. Managing Active Directory with PowerShell
        1. Active Directory-related concepts
          1. Introduction to Active Directory
          2. Namespace
          3. Object
          4. Container
          5. Trees
          6. Domain
        2. Installing an Active Directory Domain Service (ADDS)
        3. New AD server roles in Windows 2012
          1. Active Directory Certificate Services
          2. Active Directory Domain Services
          3. Active Directory Lightweight Directory Services
          4. Active Directory Rights Management Services
        4. Managing Active Directory with PowerShell
          1. Account management
            1. User management
              1. Creating an AD User
              2. Setting a user account to Expire
              3. Forcing a user to change the password at the next login
              4. Preventing users from changing the password
            2. Computer management
              1. Joining a computer to a domain
              2. Renaming a computer
          2. Group management
            1. Viewing group permissions
            2. Creating a group
            3. Adding and removing members of a group
          3. Organizational unit management
            1. Creating a new organizational unit
            2. Listing organizational units
            3. Renaming an organizational unit
            4. Modifying an organizational unit
            5. Moving an organizational unit
            6. Deleting an organizational unit
          4. Domain controller management
            1. Finding a domain controller
            2. Finding a domain controller's site
            3. Finding the global catalog servers in a forest
        5. Summary
      16. 7. Managing the Server with PowerShell
        1. Working with Server Manager cmdlets
          1. Adding roles or features by using PowerShell
          2. Advantages of PowerShell cmdlets for Server Manager
        2. Managing networking using PowerShell
        3. Managing Group Policy with PowerShell
          1. Importing a GroupPolicy module
          2. Creating GPOs with PowerShell
        4. Managing IIS with PowerShell
          1. Creating a new website
          2. Modifying IIS binding
          3. Creating an FTP site
          4. Creating a virtual directory
          5. Creating a WebAppPool
          6. Backing up and restoring WebConfiguration
        5. Managing a DNS server using PowerShell
        6. Managing Hyper-V with PowerShell
          1. Installing Hyper-V on Windows Server 2012
          2. Creating a virtual machine
          3. Starting and stopping a virtual machine
          4. Modifying a virtual machine
          5. Operating a virtual machine snapshot
        7. Managing AppLocker with PowerShell
          1. Importing the AppLocker PowerShell module
          2. Retrieving application information
          3. Retrieving an AppLocker policy
          4. Setting an AppLocker policy
          5. Generating rules for a given user or group
          6. Testing the AppLocker policy against a fileset
        8. Summary
      17. 8. Managing Unified Communication Environments with PowerShell
        1. What Exchange Management Shell is
        2. How to make Windows PowerShell understand Exchange Server cmdlets
          1. Option 1 – do it like EMS
          2. Option 2 – loading Exchange Server snap-ins
        3. Managing Exchange using PowerShell Remoting
        4. Getting started with Exchange scripting
          1. Scenario 1 – creating multiple mailboxes from CSV file
          2. Scenario 2 – creating a shared mailbox
          3. Scenario 3 – creating a resource (room/equipment) mailbox
          4. Scenario 4 – creating a distribution group
          5. Scenario 5 – defining a MailTip for a distribution group
          6. Scenario 6 – creating a dynamic distribution group
          7. Scenario 7 – creating multiple mailbox databases from a CSV file
          8. Scenario 8 – exporting mailboxes to PST files
          9. Scenario 9 – importing a mailbox from PST files
          10. Scenario 10 – hiding mailbox users from Global Address List (GAL)
          11. Scenario 11 – getting mailbox users who never accessed their mailboxes
          12. Scenario 12 – generating an organization mailbox statistics report
          13. Scenario 13 – generating a mailbox size report
        5. What Lync Server Management Shell is
        6. How to make PowerShell understand Lync Server cmdlets
          1. Loading a Lync Server module
        7. Managing Lync using PowerShell Remoting
        8. Getting started with Lync scripting
          1. Scenario 1 – enabling Lync to user accounts
          2. Scenario 2 – configuring IM file transfer filtering configuration
          3. Scenario 3 – configuring IM URL filtering
          4. Scenario 4 – bulk assignments of client PIN
          5. Scenario 5 – getting number of users using OCS/Lync
          6. Scenario 6 – setting the conference disclaimer
        9. Microsoft Office 365
        10. Office 365 and Windows PowerShell
          1. Managing Office 365 using PowerShell
          2. Managing Microsoft Exchange Online using PowerShell
        11. Summary
      18. 9. Managing Collaboration and Data Platforms with PowerShell
        1. What is SharePoint Management Shell
        2. How to make Windows PowerShell understand the SharePoint server cmdlets
        3. Getting started with SharePoint scripting
          1. Scenario 1 – creating a new site collection
          2. Scenario 2 – creating a new website
          3. Scenario 3 – creating a new quota template
          4. Scenario 4 – backing up your SharePoint environment
        4. Managing SharePoint Online using PowerShell
          1. How to load SharePoint Online Management Shell
          2. How to connect to SharePoint Online
          3. Scenario 1 – exporting a list of SharePoint Online sites to CSV
          4. Scenario 2 – restoring a deleted SharePoint Online site
          5. Scenario 3 – checking the SharePoint Online site's health status
          6. Scenario 4 – setting the SharePoint Online User as Site Collection Administrator
        5. Windows PowerShell Command Builder for SharePoint and Office 365
        6. What is SQL Server PowerShell
          1. How to load SQL Server PowerShell
            1. Method 1 – importing the SQL Server PowerShell module
            2. Method 2 – launching SQL Server PowerShell from SSMS
        7. Getting started with SQL Server scripting
          1. Scenario 1 – executing the T-SQL statement
          2. Scenario 2 – backing up the SQL Server database
          3. Scenario 3 – restoring the SQL Server database
          4. Scenario 4 – getting server instances and databases properties
          5. Scenario 5 – generating the SQL script for databases, tables, and stored procedures
        8. Summary
      19. 10. Managing Microsoft Desktop Virtualization with PowerShell
        1. What Desktop Virtualization is
        2. Understanding Desktop Virtualization components
        3. What Remote Desktop Services is
        4. Managing RDS using PowerShell
        5. Getting started with RDS scripting
          1. Scenario 1 – creating new RDS deployments
            1. Task 1.1 – creating a new virtual-machine-based deployment
            2. Task 1.2 – creating a new session-based deployment
          2. Scenario 2 – adding a Remote Desktop Server to an existing deployment
          3. Scenario 3 – adding and configuring an RD Gateway
          4. Scenario 4 – adding and configuring RD Licensing Server
          5. Scenario 5 – creating new RDS collections
            1. Task 5.1 – creating new session-based collections
            2. Task 5.2 – creating new VM-based collections
              1. Task 5.2.A – creating a Managed Pooled collection
              2. Task 5.2.B – creating an Unmanaged Personal collection
          6. Scenario 6 – setting session-based collection configuration
          7. Scenario 7 – setting VM-based collection configuration
          8. Scenario 8 – updating VM-based collections
          9. Scenario 9 – assigning Profile Disks to collections
          10. Scenario 10 – publishing Remote Desktop RemoteApp to collections
          11. Scenario 11 – configuring Remote Desktop Connection Broker for high availability
        6. Summary
      20. 11. Managing Microsoft Cloud Platform with PowerShell
        1. What Windows Azure is
        2. What Windows Azure PowerShell is
        3. Installing Windows Azure PowerShell
        4. Making Windows PowerShell understand Windows Azure cmdlets
        5. Connecting to your Windows Azure environment
        6. Getting started with Windows Azure scripting
          1. Scenario 1 – creating a new Azure Affinity Group
          2. Scenario 2 – creating a new Azure storage account
          3. Scenario 3 – assigning a storage account to an Azure subscription
          4. Scenario 4 – creating a new Azure Cloud Service
          5. Scenario 5 – creating a new SQL Azure Database Server
          6. Scenario 6 – creating a new SQL Azure database
          7. Scenario 7 – creating a new SQL Azure Database Server firewall rule
          8. Scenario 8 – provisioning the new Azure VM in Windows (quick mode)
          9. Scenario 9 – provisioning the new Azure VM in Linux (quick mode)
          10. Scenario 10 – provisioning the new Windows Azure VM (advanced mode)
          11. Scenario 11 – Adding a new endpoint to Windows Azure VM (NoLB)
          12. Scenario 12 – configuring the Windows Azure Virtual Machines load balancing (LB)
          13. Scenario 13 – creating and assigning a data disk to Windows Azure Virtual Machine
          14. Scenario 14 – moving the Local VHD to Windows Azure
          15. Scenario 15 – provisioning a new Windows Azure VM from a Disk
          16. Scenario 16 – creating Windows Azure Image from a VM
          17. Scenario 17 – exporting and importing Windows Azure VM
          18. Scenario 18 – starting, stopping, and restarting the Windows Azure VM
          19. Scenario 19 – uploading the certificate to Windows Azure
          20. Scenario 20 – generating the Azure Virtual Machine RDP file
        7. Summary
      21. 12. Integrating Windows PowerShell and System Center Orchestrator
        1. Completing your ITPA story with PowerShell and Orchestrator
          1. What System Center Orchestrator is
          2. Understanding Orchestrator workflows
          3. Orchestrator and PowerShell are better together
            1. Using PowerShell in Orchestrator workflow
            2. Using PowerShell to build Orchestrator Integration Packs
              1. Step 1 – creating the assembly file (.dll)
              2. Step 2 – creating the Integration Pack
              3. Step 3 – importing the Integration Pack into Orchestrator
              4. Step 4 – testing and using the new Integration Pack
        2. Summary
      22. Index