managing windows servers with powershell v2 james o’neill: evangelist, microsoft uk richard...
TRANSCRIPT
Managing Windows Servers with PowerShell V2
James O’Neill: Evangelist, Microsoft UKRichard Siddaway MVP
Agenda
Overview of using PowerShell V1 and V2
Products which can be managed with PowerShell today
What’s new and exciting in PowerShell V2
New PowerShell capabilities in Server 2008 R2
WHAT IS POWERSHELL
Windows PowerShellWindows PowerShell
As interactive and composable as BASH/KSHAs programmatic as Perl/Python/RubyAs production oriented as AS400 CL/VMS DCLAllows access to data stores as easy as file system
PowerShell
Automation engineCommand Shell and scripting language.NET based
DO NOT NEED TO LEARN .NET PROGRAMMING
RTW November 2006~3 million downloadsCTP 3 for Version 2 available
PowerShell – Key Features
Cmdlets
Providers
Extensible
Pipeline
The Difference is OBJECTS!
Get-Process | Where { $_.handles –gt 500 } | Sort handles | Format-Table
Get-P
rocess
Cm
dlet
Common Windows PowerShell Parser
Windows PowerShell Pipeline ProcessorW
here C
md
let
So
rt C
md
let
Fo
rmat
Cm
dlet
Scripting
Script TypesText, COM, .NET PowerShell cmdlets
Data TypesFlat File, .NET, XMLWMI, ADSI, ADO.NETSQL
PowerShell adoption
MicrosoftExchange 2007Windows Server 2008 (R2)SC Data Protection ManagerSC Operations Manager 2007Compute ClusterSQL Server 2008OCS Resource KitSBS & EBS 2008
Third partySpecial Operations SoftwareQuest AD cmdletsPowerGUIPowerGadgetsSdmsoftwareIBM Websphere MQCitrixPowerShell Community Extensions
Issues
Default install mode won’t run scriptsSet-ExecutionPolicy
No file associationCan’t automatically run scripts or double click
No remoting – coming in V2Can use .NET and WMI
Current working directory is NOT on PATH.\myscript.ps1
Does not load all .NET assembliesUse [Reflection.Assembly]::LoadWithPartialName(" Microsoft.SqlServer.Smo ")
Slow load?
Aliases
Please:
Do not use aliases in scripts or posts to forums, blogs or
articles etc
PowerShell Basics
Demo
POWERSHELL VERSION 2
PowerShell V2
It is a CTP!! It will change!!!!!!! DO NOT USE IN PRODUCTION !!!!!!!RemotingBackground jobsAdvanced FunctionsTransactions – depend on provider
Registry only
Debugging PowerShell ISE
Win Remote Management
Jobs and RemotingWindows Remote Management Service
WinRM
WS-Management protocol
Local AND remote machinesRun as administrator
Configure AND use
CTP only on Vista and Windows 2008
PowerShell Sessions
RemotingLocal or remote machine
Creates PowerShell sessionPersistent connectionSpeeds response
PowerShell Jobs
Asynchronous Job – get, receive, remove, start, stop, wait
Start-Job or -AsJobGet-Help * -Parameter AsJob
Local or remoteReceive-Job
View results (& delete job ?)
PowerShell Remoting
Some cmdlets have ownGet-Help * -Parameter ComputerName
Need PowerShell V2 local and remoteInvoke-Command or Interactive
Use a sessionCan work with jobs
Advanced Function
Aka script cmdletScript not compiledVariation on function
Works on pipeline
Cannot associate help fileSee get-help about_functions_advanced*
WMI
WMI Type Accelerators[WMI][WMIClass][WMISearcher]
Improved support in V2Get-WMIObject improvedInvoke-WMIMethodSet-WMIInstanceRemove-WMIObject
PowerShell V2 issues
CTP = changingScripts may break
Check release notes
Cmdlet name clashesEspecially with PSCX
More complicatedNew keywords e.g. data
PowerShell V2
Demo
Break
PowerShell in Windows Server 2008 R2
Demo
Summary/Call to Action
PowerShell can be used to administer large and growing parts of your environmentNow available at: www.microsoft.com/downloads
Search for PowerShell
Try it, Deploy it, Use it, Share
For More Information
User group:http://www.get-psuguk.org.uk
My Bloghttp://richardsiddaway.spaces.live.com
Get-PSUGUKUK PowerShellUser Group
Books
Books
Name:Email:
Any Questions?
Reference Slides
Scripting with COM
Access existing instrumentationBind to COM objects
$fso = New-Object -ComObject Scripting.FileSystemObject$m = [System.Runtime.InteropServices.Marshal]$word = $m::GetActiveObject("Word.Application")
Invoke methods/access properties$fso.GetDrive(“C:”)$fso.VolumeName = “System Drive”
Understand/extend instrumentationExtend and discover properties/methods
Update-TypeData Office.Word.Types.ps1xml$fso | Get-Member
Manipulate and format resultsDefine and import custom formating
Update-FormatData Office.Word.Format.ps1xml$word.RecentFiles | Sort name | Format-Table
Allows more simpler/more powerful COM scripts because of utilities and formatting
Scripting with WMI
PowerShell provides native WMI supportGet-WmiObject
Allows for inspection of WMI namespaceGet-WmiObject –list [-Namespace xx]Get-WmiObject –Class xx –Namespace xx –Property xxx – Filter xxx –ComputerName xxx –Credential xxx
Native language support[WMI] “\\JPSDESK10\root\cimv2:Win32_Process.Handle="0“[WMICLASS] "ROOT\cimv2:WIN32_PROCESS"[WMISEARCHER]"select * from Win32_process WHERE Name = 'calc.exe'"
Scripting with .NET
PowerShell provides native access to any .NET classCreate any object
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")$d = New-Object System.DateTime 2006,12,25
Access Properties/Invoke Methods$d.DayOfWeek$d.AddDays(-30)
Access Statics[DateTime]::Now[DateTime]::IsLeapYear(2006)
Allows admins to easily access and leverage a huge API set because of scriptability, utilities and formatting
Scripting with XML
PowerShell provides native XML supportNative datatype
$x=[xml]"<a><b><c>TEST</c></b></a>“$b =[xml](type c:\i386\mssecure.xml)
Native syntax to access “data” view of properties$b.BulletinDataStore.Bulletins.Bulletin[0]
Access to XML methods $b.BulletinDataStore.SelectNodes(“//Patch”)
XML properties available through PSBase property$b.BulletinDataStore.PSBase.innerXml
Scripting with Text
Invoke existing tools Existing command run directly after variables are expanded
Harvest data from existing toolsParse output into variables using text utilities.
Pipe data to SELECT and use –FIRST and –LAST Select-String <REGEX> <Path>Dir | Select-String <REGEX>[DateTime]”12/25/2006 7:00”([DateTime]”12/25/2006 7:00”).AddDays(-30)
Use functions/scripts to wrap the commands and convert output to objects or provide standard syntax
Safely process textUse CLR types via Windows PowerShell to safely parse text
[URI]” http://blogs.msdn.com/powershell/archive/2006/04/25/583234.aspx”
Allows admins to get 2-10x more power out of existing commands because of scriptability
Active Directory
AD cmdletshttp://www.quest.com/activeroles-server/arms.aspx
PowerGUIhttp://www.powergui.org
Special Operations Softwarehttp://www.specopssoft.com/
SDMSoftwarehttp://www.sdmsoftware.com/freeware.php
IIS 7
The following walkthroughs are available on the www.iis.net web site:
PowerShellAn Introduction to Windows PowerShell and IIS 7.0http://www.iis.net/go/1212Writing PowerShell Command-lets for IIS7http://www.iis.net/go/1211
AppCmdGetting Started with AppCmd in IIS 7.0http://www.iis.net/go/1222Command Line Administration with IIS7 – AppCmdhttp://www.iis.net/go/954