• No results found

Windows PowerShell Fundamentals

N/A
N/A
Protected

Academic year: 2021

Share "Windows PowerShell Fundamentals"

Copied!
42
0
0

Loading.... (view fulltext now)

Full text

(1)

Windows PowerShell

Fundamentals

Steven Murawski Senior Windows Systems Engineer Microsoft MVP

This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/

or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.

(2)

Who I am

Name – Steven Murawski

Occupation – Senior Windows System

Engineer

Blog – UsePowerShell.com

Twitter - @StevenMurawski

(3)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

(4)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

(5)

What is PowerShell?

(6)

What is PowerShell?

(7)

What is PowerShell?

Most importantly though it is an Automation

Tool.

PowerShell offers a unifying management

surface in which to manage your Windows (and

other) environment.

(8)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(9)

Terminology

Cmdlet

Functions

Objects

(10)

Terminology

Cmdlets

– The basic unit of work in PowerShell.

– These are PowerShell’s native commands. – They are called cmdlets (small commands)

because they embrace the Unix philosophy of small tools which can be used compose new solutions

(11)

Terminology

Functions

– Functions are a series of PowerShell statements (or commands) that are given a name and saved in memory for a particular session.

– There are several types of functions:

• V1 style function

• Filter

(12)

Terminology

Objects

– PowerShell is an object-based shell.

– Objects are a binding of data and actions.

– What this really means is that when you execute a command, you can more easily ask questions of the result.

– Being object based also gives PowerShell the

ability to provide generalized format, display, and export capabilities.

(13)

Terminology

Pipeline

– The pipeline is a central concept in PowerShell which allows you to take the output from one command and make it the input for the next command.

– It has long been the case that shell commands can take input from other commands (or files, or other sources).

– The pipeline in PowerShell can leverage the object

based and utilize some components of the runtime to make transitions between commands more effective.

(14)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(15)

The Big Four

Navigational And Discovery Commands

– Get-Command – Get-Help

– Get-Member – Get-PSDrive

(16)

The Big Four

Get-Command

– Get-Command will list any valid command (executables, functions, cmdlets, aliases).

– It can also provide some additional metadata about PowerShell commands and scripts.

(17)

The Big Four

Get-Help

– This is the “man” equivalent for PowerShell. – Get-Help offers several levels of help

• Basic

• Detailed

• Full

• Examples

(18)

The Big Four

Get-Member

– Since PowerShell is an object-based shell,

Get-Member allows you to examine the objects output from different commands.

– This is probably the most important discovery command.

(19)

The Big Four

Get-PSDrive

– PowerShell offers the capability to expose various information sources (providers) like a file system. – Get-PSDrive lists the mapped providers and where

(20)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(21)

Working From the Shell

Navigating Providers

– Providers offer a way to navigate different data sources via the same commands.

Providers

– File System – Registry

(22)

Working From the Shell

Navigating the File System

– Items and Containers – Item Properties

(23)

Working From the Shell

Digging in the Registry

– PowerShell provides access to the registry via a provider. This allows the registry to be navigated like the file system.

– Keys and subkeys are represented as items (like files and directories.

– Registry values and data are represented as properties of the items.

(24)

Working From the Shell

Other Providers

– Built in • Alias • Certificate • File System • Function • Registry • Variable • WSMan – Others • SQL Server • Active Directory

(25)

Working From the Shell

Dealing with Objects

– Formatting Output – Filtering Output – Using the Pipeline

(26)

Working From the Shell

Formatting Output

– Format-Table – Format-List – Format-Custom – ConvertTo-XML – ConvertTo-HTML – ConvertTo-CSV – Export-CliXML – Export-CSV

(27)

Working From the Shell

Filtering output

– Native Filtering in Commands

• Usually preferred, but can vary based on the command and data type.

• If the target of the command is remote, filtering could be done at the source.

– Where-Object

• Uses a scriptblock (PowerShell statements surrounded by braces)

• Works on any object in the PowerShell Pipeline

(28)

Working From the Shell

Using the Pipeline

– PowerShell pipes objects.

– Cmdlets, scripts, and functions can take full objects as arguments.

– Properties of objects can be automatically

mapped to parameters of cmdlets, scripts, or functions.

(29)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(30)

Working with Workstations and

Servers

Working with WMI

– Get-WMIObject is the key command when working with WMI.

– Get-WMIObject –List

– What’s stored in WMI? Just about everything!

• Hardware information

• System Configuration

• Application Data

(31)

Working with Workstations and

Servers

Editing the Registry

– Via the Provider

• Can use it locally

• Can use it remotely if PowerShell Remoting is enabled.

– Using .NET

• More familiar to .NET developers.

– Using WMI

(32)

Working with Workstations and

Servers

Working with Text

– Select-String – Operators • Match • Replace • Split – Regular Expressions

(33)

Working with Workstations and

Servers

Working with Remote Machines

– WMI

• Available on most machines.

• Requires a knowledge of WMI (which is not very consistent)

– PowerShell Remoting

• Requires Windows XP SP3/Server 2003 SP2 or higher and WinRM

(34)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(35)

Working with Active Directory

• ADSI

– Available on any machine

– Obscure

• Quest’s AD Cmdlets – Task based

– Excellent Coverage

– Server 2003 Domains or above

– 3rd Party

• Microsoft’s AD Module

– Only available on Windows 7 or Server 2008 R2

– Server 2003 Domains or above.

(36)

Working with Active Directory

Common Tasks

– Resetting Passwords – Finding Disabled Users

(37)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(38)

Working with Exchange

Common Tasks

– Monitor Message Queues (Exchange 2003)

– Monitor Message Queues (Exchange 2007/2010) – Identify all ActiveSync Devices Connected

(39)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(40)

V3 Sneak Peak

PowerShell V3 – Windows 8

– Workflows – Resilient Sessions – Disconnected Sessions – Autoloading of Modules – And more…

(41)

Agenda

What is PowerShell?

Terminology

The Big 4

Working from the Shell

Workstations and Servers

Active Directory

Exchange

PowerShell V3 Sneak Peak

(42)

Q and A

I’m sure no one has any questions, so we can

just hang out..

But on the off chance that some has any

questions, where can we get some answers?

– PowerShell.Org – ServerFault.com

References

Related documents

2011, Member, Department of Criminal Justice Instructor Search Committee 2010 to 2012, Representative, College of Health & Public Affairs Faculty Council Washington

If you’re a beer buff, take a guided tour at Deschutes Brewery to learn more about how the craft beer scene got its start in Central Oregon, then visit a few.. of the city’s

Considering the research significance, the motivations and gaps mentioned above, this PhD project aims to: (1) investigate the inconsistencies of different measurement

Such a collegiate cul- ture, like honors cultures everywhere, is best achieved by open and trusting relationships of the students with each other and the instructor, discussions

One possible explanation for di fferent effects on immigrants and natives as well as for men and women may be di fferent resource allocation within intermar- riage: Native partners

The aim of the interviews was to find out how the transition project had supported survivors and their children in this period and therefore we did not ask any questions

Abbreviations: cDNA, complementary DNA; CNV, choroi- dal neovascularization; DPBS, Dulbecco’s phosphate-buffered saline; EST, expressed sequence tag; HUVEC, human umbil- ical

National concerns about quality of care and safety Shortages of nursing personnel which demands a higher level pf preparation for leaders who can design and assess care.. Shortages