SUNGARD SUMMIT 2007 sungardsummit.com 1 Microsoft PowerShell Presented by: Jeff Modzel March 22, 2007 A Community of Learning
Agenda Introduction to PowerShell PowerShell Power Developer Angle Long Term Strategy 2
SUNGARD SUMMIT 2007 sungardsummit.com 3 Introduction to PowerShell A Community of Learning
What is PowerShell? New command-line shell and scripting language Multiple perspectives for use: System Administrators Developers Object based, not text based (.NET 2.0 objects) Can still use the regular, old.exe s you re used to! Formerly code-named Monad Free download from Microsoft 4
What does it look like? 5
Cmdlets (pronounced command-lets ) Command that performs a single function Operate on objects Use a verb-noun naming convention Can chain cmdlets together to do powerful things About 130 built-in cmdlets Can create your own cmdlets 6
Available cmdlets use get-command 7
More examples: Get-command Get-content/set-content Get-childitem Get-process Get-service Get-help Shows all cmdlets installed in the shell. Reads a text file/writes a text file. Equivalent of dir in DOS, for the file system Retrieves the running processes, equivalent to tasklist.exe Retrieves running services, equivalent to sc.exe Gets help for a specific cmdlet 8
Scripting Support New scripting language, object oriented-like Language for manipulating.net objects. Consistent environment for using cmdlets. Support complex tasks, without making simple tasks more complex. Consistent with higher-level languages used in.net programming, such as C#. 9
Scripting Language Variables begin with a $ (variables have scope) Variables are objects and have properties/methods Has all the constructs you d expect from a modern language: if/then, while, for, foreach, do, switch, trap/throw Scripts can be stored in script files (.ps1 extension) or even other variables. Can create and store functions in shell for reuse 10
SUNGARD SUMMIT 2007 sungardsummit.com 11 PowerShell Power A Community of Learning
Object Pipeline Pipes connect cmdlets Pipes pass objects, not text Objects package together related information Examples: get-process format-list out-file c:\list.txt get-service where-object {$_.Status eq Running } get-childitem sort-object length get-content c:\list.txt select-object first 5 get-date get-member 12
General use cmdlets Filtering pipeline objects use where-object, selectobject, sort-object and group-object. Format pipeline objects for output (or other cmdlets) use format-list, format-table, format-wide and formatcustom. 13
Text File manipulation Use set-content, add-content and get-content to read, append and write text files. Can still use > and >> redirection Use import-csv and export-csv to read and write comma separated values files. Note: Excel can use CSV files. Use import-clixml and export-clixml to read and write XML based representations of PowerShell objects 14
Variables Always begin with a $ Can contain any other characters after $ but need to use curly braces No need to declare, just create and use Have scope Variables are.net objects Examples: $var = 1 ${student name} = Joe Smith $date = get-date $a = get-process # returns an array 15
.NET, COM and WMI Can access.net classes, COM objects and WMI with new-object and get-wmiobject. Examples: $wc = new-object Typename System.Net.WebClient $list = new-object System.Collections.ArrayList [System.IO.File]::Exists( c:\junk.txt ) $wsh = new-object ComObject WScript.Shell $fso = new-object Com Scripting.FileSystemObject $ie = new-object Com InternetExplorer.Application $excel = new-object Com Excel.Application 16
WMI continued Windows Management Instrumentation (WMI) is an administration technology for Windows Examples: get-wmiobject class win32_computersystem get-wmiobject win32_operatingsystem Get-wmiobject win32_logicaldisk Get-wmiobject list # show all classes 17
get-wmiobject examples 18
Providers Provides connectivity to a type of resource (data store) File system Registry Alias Environment (windows environment) Function Variable Certificate (digital certificates) PowerShell has it s own concept of a drive location for a data store. See get-psdrive and get-psprovider 19
Scripts PowerShell code can be saved in script files for reuse Use a.ps1 extension Don t forget - can call regular old.exe s in script! Type name of file minus the.ps1 extension and interactive shell will search for the file in the environment Path variable. Or Type full path name with the ps1 extension. Execute with a period. To run the script in the current scope. Interactive shell looks for first for an alias, then function, then cmdlet, then script and finally an external.exe. Execute from DOS\Batch\Windows powershell.exe c:\myscript.ps1 20
Customizing the shell environment Use a profile script to set aliases, functions, map drives or any other startup commands Profiles don t exist by default Profiles are read in order, the last one wins 21
Profiles %windir%\system32\windowspowershell\v1.0\profile.ps1 This profile is loaded for all users. %windir%\system32\windowspowershell\v1.0\ Microsoft.PowerShell_profile.ps1 This profile is loaded for all users, and only for the default instance of PowerShell. %UserProfile%\My Documents\WindowsPowerShell\profile.ps1 This profile is loaded per-user, and affects all versions of PowerShell which are installed. %UserProfile%\\My Documents\WindowsPowerShell\ Microsoft.PowerShell_profile.ps1 This profile is loaded per-user, but only affects the default instance of PowerShell. 22
Security Execution policy determines if user can load configuration files, run scripts and/or require digital signatures for scripts. Integrated with Active Directory / Group Policy Policies are: Restricted, AllSigned, RemoteSigned and Unrestricted Use get/set-executionpolciy to view and change Can use certificates to sign scripts (see setauthenticodesignature) 23
SUNGARD SUMMIT 2007 sungardsummit.com 24 Developer Angle A Community of Learning
Additional things you can do with PowerShell Author cmdlets, providers and filters in Visual Studio Create your own custom shell (typically for integration with other applications) As of 2/7/07, need to install the Windows PowerShell SDK which is part of the Microsoft Windows SDK for Windows Vista. 25
Steps to author a cmdlet Create Visual Studio project Add desired cmdlets and snap-in class Compile to a.dll Register the.dll with installutil.exe (verify with getpssnapin registered) Add snap-in to the shell with add-pssnapin YourSnapIn Verify cmdlets have been added to the shell with getcommand Run new cmdlets! Can use export-console to save state of console for later reuse 26
Creating a custom shell Use the make-shell.exe utility from the SDK Allows creation of customized shells primarily for specialized snap-ins 27
SUNGARD SUMMIT 2007 sungardsummit.com 28 Long Term Strategy A Community of Learning
Where does it fit in Microsoft s strategy? Strategic commitment to.net, PowerShell is built on.net Eventually become part of Windows (not for Vista or Longhorn, though) Exchange 2007 has PowerShell interface known as Exchange Management Shell Some IIS 7 integration 29
Where to get it? Requirements? http://www.microsoft.com/technet/scriptcenter/topics/m sh/download.mspx 2 meg download but needs.net 2.0 OS requirements: Windows XP SP 2, Windows Server 2003, Vista and Longhorn 30
Useful links Homepage http://www.microsoft.com/windowsserver2003/technologie s/management/powershell/default.mspx PowerShell Team Blog http://blogs.msdn.com/powershell/ Other good PowerShell sites http://thepowershellguy.com/blogs/posh/ http://www.microsoft.com/technet/scriptcenter/hubs/msh. mspx 31
Questions & Answers 32
Thank You! Jeff Modzel jeff.modzel@sungardhe.com Please complete the online class evaluation form for: Microsoft PowerShell SunGard, the SunGard logo, Banner, Campus Pipeline, Luminis, PowerCAMPUS, Matrix, and Plus are trademarks or registered trademarks of SunGard Data Systems Inc. or its subsidiaries in the U.S. and other countries. Third-party names and marks referenced herein are trademarks or registered trademarks of their respective owners. 2006 SunGard. All rights reserved. 33