what is powershell? why powershell? what is new in powershell 2.0? advanced functions modules ...

24

Post on 20-Dec-2015

249 views

Category:

Documents


3 download

TRANSCRIPT

Windows Powershell Scripting

Krishna Kumarhttp://smtpport25.wordpress.com

Agenda

What is Powershell? Why Powershell? What is new in Powershell 2.0?

Advanced Functions Modules Remoting Eventing Background Jobs Power Shell ISE Transactions Language changes 100+ new cmdlets

PowerShell is an object-oriented programming language and interactive command line shell for Microsoft Windows

Built and Integrated with .NET Framework Included in Windows Server® 2008 R2 and Windows® 7 Its is basically to IT guys to automate system tasks It uses cmdlets, it’s a small .net classes Easily composed

Create higher level tools for complex operations Provides a common management automation platform

PowershellWhat is Powershell ?

Why Powershell ?

IT Pros want a powerful way to manage datacenters Designed to reduce the cost and effort required to manage your IT

infrastructure Reduces time-to-results Traditional Windows Shell is text based and parsing is nightmare Designed to help standardize and automate all of your management

processes Easy to adopt, easy to learn, and easy to use Click and manage will not scale End-to-end manageability across server roles

Active Directory®, Exchange, Group Policy, etc. Reusability Extensibility

What is new in PowerShell v 2.0? What is new in PowerShell 2.0?

Advanced Functions Modules Remoting Eventing Background Jobs Improved Help PowerShell ISE Transactions New Operators 100+ new cmdlets

Modules

Modules are self contained reusable code, It contain single function or

multiple function which is independent to itself

Modules are Next Version of Snap in

Require some manual efforts to create modules

Get-Module Import-Module New-Module Remove-Module

Advanced Function

Advanced Functions provide help, parameter tab-completion, and cmdlet semantics that make it easy for other people to use your modules

We don’t want to go back to find the source code to find functions in the modules

We don’t want ever time to see what parameter module accepts

You want option -WHATIF –CONFIRM –VERBOSE from the function in modules

Demo

Remoting Built on top of WS-Management Requires administrator privileges

To enable remoting To connect to a remote session

Remoting output Serialized property bags; not live objects

Related cmdlets New-PSSession Get-PSSession Remove-PSSession Export-PSSession Import-PSSession Enter-PSSession Exit-PSSession Invoke-Command

Remoting

Interactive remoting Works as if you are working at remote console Enter-PSSession is used

Implicit remoting Gets remote commands in to local session Import-Session

Saving remote session to disk Export-Session cmdlet is used

Custom session configuration can be created to restrict what a remote user can perform

Demo

New Operators

Splatting operator (@): PowerShell V2 supports splatting operator (@) to pass a collection of parameters

-Split: The -split operator enables a user to split a string into an array of substrings, based on a separator.

–Join: The -join operator concatenates multiple strings from a string array into a single string, separated by the separator.

Demo

Eventing

Eventing allows actions to be taken or respond to the asynchronous notifications when certain events occur

1. BitsTransmodule: We can transfer files or download files from internet and we can configure to monitor download operation. Once download completes eventing can be configured to notify the download completion status

Background Jobs

Background Jobs are used to Run the Jobs in the Back Ground and allows to continue with other tasks in the shell

Start-Job : Start the new Background Job Get-Job : Gets the list of job and there status Receive-Job : Receive Job is to get the result of the jobs running Stop-Job : Stop to stop the current running jobs Wait-Job : Wait for the prompt until the job continues Remove-Job : removes the Job details

Demo

PowerShell ISE(Integrated Scripting Environment)

Powers hell ISE, formerly known as Graphical Powershell, is a graphical development environment and command prompt alternative.

You can view your PowerShell scripts, insert commands,debug and view the output all at the same window

Demo

Transaction

PowerShell allows ability to develop full transaction-based scripts complete with cmdlets for starting, committing, and rolling back a transaction in the event of an error or other condition.

This capability starts to make PowerShell an attractive choice for even the most complex business processes as administrators can be more sure that scripts can return data to its original state if necessary.

Start-Transaction Get-Transaction Use-Transaction Complete-Transaction Undo-Transaction

Demo

Over 240 Cmdlets Installed by defaultRemoting

Disable-PSSessionConfigurationEnable-PSRemotingEnable-PSSessionConfigurationEnter-PSSessionExit-PSSessionExport-PSSessionGet-PSSessionGet-PSSessionConfigurationImport-PSSessionInvoke-CommandNew-PSSessionNew-PSSessionOptionNew-WebServiceProxyRegister-PSSessionConfigurationRemove-PSSessionSet-PSSessionConfiguration

Custom SessionsDisable-PSSessionConfigurationEnable-PSSessionConfigurationGet-PSSessionConfigurationNew-PSSessionOptionRegister-PSSessionConfigurationSet-PSSessionConfigurationUnregister-PSSessionConfiguration

ComputersAdd-ComputerCheckpoint-ComputerDisable-ComputerRestoreEnable-ComputerRestoreGet-ComputerRestorePointRemove-ComputerReset-ComputerPasswordRestart-ComputerRestore-ComputerStop-ComputerTest-Connection

OtherClear-HistoryDebug-ProcessExport-FormatDataGet-FormatDataGet-RandomImport-LocalizedDataOut-GridViewSelect-XmlSend-MailMessageSet-StrictModeStart-ProcessTest-ComputerSecureChannelUpdate-ListWait-Process

DebuggingDisable-PSBreakpointEnable-PSBreakpointGet-PSBreakpointGet-PSCallStack Remove-PSBreakpointSet-PSBreakpoint

Type ConversionAdd-TypeConvertFrom-CsvConvertFrom-StringDataConvertTo-CsvConvertTo-Xml

DiagnosticsClear-EventLogExport-CounterGet-CounterGet-HotfixGet-WinEventImport-CounterLimit-EventLogNew-EventLogRemove-EventLogShow-EventLogWrite-EventLog

Resources

Windows Powershell 2.0 CTP for XP and Vistahttp://www.microsoft.com/technet/scriptcenter/topics/msh/download2.mspx

Newsgroup: Microsoft.Public.Windows.Powershell

PowerShell Team Blog: http://blogs.msdn.com/Powershell

Scripting Guys Script Center: microsoft.com/technet/scriptcenter

Thank You

Krishna Kumarhttp://smtpport25.wordpress.com