• No results found

SUNGARD SUMMIT 2007 sungardsummit.com 1. Microsoft PowerShell. Presented by: Jeff Modzel. March 22, 2007 Course ID 453. A Community of Learning

N/A
N/A
Protected

Academic year: 2021

Share "SUNGARD SUMMIT 2007 sungardsummit.com 1. Microsoft PowerShell. Presented by: Jeff Modzel. March 22, 2007 Course ID 453. A Community of Learning"

Copied!
33
0
0

Loading.... (view fulltext now)

Full text

(1)

A Community of Learning

SUNGARD SUMMIT 2007 | sungardsummit.com 1

Microsoft PowerShell

Presented by: Jeff Modzel

March 22, 2007 Course ID 453

(2)

Agenda

• Introduction to PowerShell • PowerShell Power

• Developer Angle

(3)

A Community of Learning

SUNGARD SUMMIT 2007 | sungardsummit.com 3

(4)

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

(5)

5

Course ID 453

(6)

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

(7)

7

Course ID 453

(8)

More examples:

Get-command Shows all cmdlets installed in

the shell.

Get-content/set-content Reads a text file/writes a text

file.

Get-childitem Equivalent of dir in DOS, for the

file system

Get-process Retrieves the running

processes, equivalent to

tasklist.exe

Get-service Retrieves running services,

equivalent to sc.exe

(9)

9

Course ID 453

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#.

(10)

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.

(11)

A Community of Learning

SUNGARD SUMMIT 2007 | sungardsummit.com 11

(12)

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

(13)

13

Course ID 453

General use cmdlets

• Filtering pipeline objects use where-object,

select-object, sort-object and group-object.

• Format pipeline objects for output (or other cmdlets) use list, table, wide and

(14)

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

(15)

15

Course ID 453

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

(16)

.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

(17)

17

Course ID 453

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

(18)
(19)

19

Course ID 453

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.

(20)

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

(21)

21

Course ID 453

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

(22)

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.

(23)

23

Course ID 453

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

(24)

SUNGARD SUMMIT 2007 | sungardsummit.com 24

(25)

25

Course ID 453

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

(26)

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

get-pssnapin –registered)

• Add snap-in to the shell with add-pssnapin YourSnapIn • Verify cmdlets have been added to the shell with

get-command

• Run new cmdlets!

• Can use export-console to save “state” of console for later reuse

(27)

27

Course ID 453

Creating a custom shell

• Use the make-shell.exe utility from the SDK

• Allows creation of customized shells – primarily for specialized snap-ins

(28)

SUNGARD SUMMIT 2007 | sungardsummit.com 28

(29)

29

Course ID 453

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

(30)

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

(31)

31 Course ID 453

Useful links

• Homepagehttp://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.

(32)
(33)

33

Course ID 453

Thank You!

Jeff Modzel

[email protected]

Please complete the online class evaluation form for:

Microsoft PowerShell

Course ID 453

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.

References

Related documents

Next, we would like to ask you to rate the general quality of this tourist destination offer on a scale 1 -5, where »1« means the quality of the offer is very poor and »5« -

Figure 7(d) presents that when the defender’s target valuation increases, the defender increases the defensive investment and her utility decreases; while the attacker gains when

• Drive axle tyre for all types of On/Off commercial vehicles.. • Robust tread pattern

An associated development was the publication of the textbook, Introductory Indigenous studies in education: The importance of Knowing, (Phillips & Lampert, 2005), with chapters

♦ The CFBE while providing a rough and easy way to look at cashflow requirements / cash flow issues for the short term, can also be used with banks to show that not only is

The proximity optimiza- tion consists of timing and location aware cell clustering and incremental placement enforcing the clusters.. Experiments are performed on the ICCAD

The ability offered by TSO for WPWE OSD is published on TSO’s website and is equivalent to the total capacity (contractual capacity) acquired by the DSO from

Considering different codeword reuse in different MIMO modes and consumption of control signaling, here is how to calculate theoretic