Powershell For Developers
-
Upload
ido-flatow -
Category
Technology
-
view
279 -
download
0
description
Transcript of Powershell For Developers
Ido Flatow
PowerShell For Developers
About Me• Senior Architect, Sela Group, Israel• Co-author of Microsoft courses – “WCF 4” and “Developing
Windows Azure and Web Services”• Co-author, “Pro .NET Performance” and “Pro Single Page
Application Development”• Microsoft ASP.NET/IIS MVP• Focus on server, web, cloud, and DevOps• Manager of the Israeli Web Developers User Group
What is PowerShell?
• A command line interface• A scripting environment• A tool to automate routine tasks• Something that will simplify your life• The next generation of command-line
Introducing PowerShell
DEMO
The Most Important Cmdlets• Get-Help (help)• Get-Command (gcm)• Get-Member (gm)
Some Cmdlet Examples
Basic functions:• Get-ChildItem (= dir)• Set-Location (= cd)• Copy-Item (= copy)• Remove-Item (= del)
Management:• Start-Service• Import-Certificate• Write-EventLog• New-WebAppPool
Object treatment:• Where-Object (?)• Select-Object (select)• Foreach-Object (%)• Compare-Object (diff)
Layout:• Format-List• ConvertFrom-Json• Out-GridView• ConvertTo-Xml
Why is PowerShell so Great?
• The output of a command is an object• Objects can be pipelined as input• Built on top of the .NET Framework• Easy to discover what you can do• Has both command-line and GUI • Supports debugging• Runs locally and remotely
Piping Examples
Get-ChildItem -Filter "*.cs" –File -Recurse | `Measure-Object Length -Sum
( Get-WmiObject -class win32_process | ` ? {$_.ProcessName -eq 'w3wp.exe'}).GetOwner() | `Select -property domain, user
Get-Process | ? {$_.PrivateMemorySize64 -gt 50MB} | `Out-Host -Paging
PowerShell Pop QuizGet-EventLog "Application" `| ? {$_.Source -like 'ASP.NET*' –and ` $_.Message -match 'Event code: (\d+).*'} `| ? {$matches[1] -eq '3005'} `| foreach { new-object PSObject -prop @{ ` Time = $_.TimeWritten.Date.ToString("yyyy/MM/dd"); Message = ($_.Message | Select-String `
'(Exception message: )(.*)' ).Matches.Groups[2].Value }} `| group Time, Message `| select Count, ` @{Name="Time";Expression={$_.Name.Split(",")[0].Trim()}}, ` @{Name="Exception";Expression={$_.Name.Split(",")[1].Trim()}} `| sort -desc Time `| out-gridview
Tools of the Trade
PowerShell Command Line
PowerShell ISE
SAPIENS PowerShell Studio
PowerShell Using .NET or .NET Using PowerShell?
• You can actually do both!• Call .NET code from PowerShell• Create new C# classes in PowerShell• Execute PowerShell script from .NET
PowerShell and .NET Integration
DEMO
PowerShell For Developers
• Work with XML and JSON content• Access system resources, such as registry, files, and
certificates• Transform text files using regular expressions• Control platforms, such as IIS, MS-SQL, and Azure• Cleanup TFS content from VS solutions and project• Create automatic deployment scripts• Interact with SOAP and REST services
Platform-specific Cmdlets (IIS)
Platform-specific Cmdlets (MS-SQL)
PowerShell for Developers
DEMO
Resources
Everything PowerShellhttp://PowerShell.org
Script Repositoryhttp://www.poshcode.orghttp://gallery.technet.microsoft.com/scriptcenter
Blogshttp://blogs.msdn.com/PowerShellhttp://blogs.technet.com/heyscriptingguy
@idoflatow [email protected] http://blogs.microsoft.co.il/idof
Presentation and Sampleshttp://1drv.ms/1n8w1nM
Questions
Thank You