Windows PowerShell for Developers Let the force be with you PowerPoint PPT Presentation

presentation player overlay
1 / 30
About This Presentation
Transcript and Presenter's Notes

Title: Windows PowerShell for Developers Let the force be with you


1
Windows PowerShell for DevelopersLet the force
be with you
  • ????? ???????????, Seavus
  • http//mkdot.net/blogs/dejan

2
Presenter.ToString()
  • Technology Line Officer _at_ Seavus
  • Co-founder on Macedonian .NET User Group
    (http//mkdot.net)
  • MCPD, MCSD, MBSC
  • Personal blog at http//mkdot.net/blogs/dejan

3
????????
4
??????
  • ?????
  • ??? ? Windows PowerShell?
  • ??????? ????????
  • ???????? ????????
  • ???????
  • ??????? ? ????????

5
??? ? PowerShell?
  • ???????? ?????? ?? ???????? ????
  • ??? ?
  • Shell
  • ????? .bat ????
  • VBScript ??????
  • ???????? ???????? ?? ????????????????
  • ???????? ???????? ?? ????????????

6
???????? ? ??????????? ??...

Command Line
Unix shell
7
(No Transcript)
8
???????? ?????????? shell ? ?????? ?????
  • 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 to access as filesystem

9
Windows PowerShell
  • PowerShell ? ???????? ???????? ???????? ??????
    ?????????? .NET ?????????
  • ??????? ? ???????? ???????? ???????, cmdlet-???
    ???????? ??????????? ???????, ????????? ??
    ?????????? shell-??? ??? ??????? ?? ?????
  • Verb-Noun ?????????
  • Get-Command / Get-Help / Get-Member

10
??????????? ?????????????? ???????
  • ???????????
  • ???????????? ??? ????????????
  • ?????? ????????
  • ??????? ??? ?? ????????
  • ???? ??? ?????? ??????
  • ???????? ??? ????????
  • ?????????????? ?????????
  • .NET, native code, COM, WMI, ADSI, XML, ADO,
    WebServices, WSMAN...
  • ?????????? ????????? ?? ????????? ????????????

In-Proc, Local, RemoteRuntime Engines
????? ??????? ?? ???????????
11
?? ???? ? ????????
12
??????? ???????
  • ???????? Get-Command
  • ?? ????? Get-Help with command.
  • ?????? ????? ?? ?????????
  • ?? ???????
  • Get-Help Get-Command examples
  • Get-Help Get-Command detailed
  • ?? ???? ???????? ??????
  • Get-Help Get-Command full

13
DEMO
  • ??????? ???????? ? ????????

14
??????? ??????????
  • Alias
  • cd set-location
  • Dir get-childitem
  • Cmdlet
  • ?????? ?? PowerShell
  • Function
  • ?????? ????
  • Provider
  • ???????????? ?????????
  • Get-PSdrive
  • Snapin
  • ????? ?? PowerShell ???????????????

15
PoSH ??????
  • Verb-noun write-host, where-object, get-content
  • ?????? ????
  • variable
  • Scope global, script, local
  • foo bar
  • anArray 1,2,3,4
  • intsomeInt 5
  • xmlxmlDoc ltagtltbgtstufflt/bgtlt/agt
  • MyClass.MyTypesomeThing
  • ??????? ?? ?????????????

16
?????? ? ???????? ?? ?????
  • ?????????
  • -eq
  • -lt / -gt
  • -le / -ge
  • -like / -notlike
  • -match / -imatch
  • ????????
  • If
  • switch
  • help about_comparison_operators

17
DEMO
  • ?????????, ?????????, ???????? ?? ???,
    ?????????????

18
Pipeline
  • ?? ? System.Object
  • ????? ??? ?? ? ????? ???????????!
  • Get-ChildItem C\Windows\ Where-Object
    _.Name.Length -gt 15 Select-Object -Last 2
    Sort-Object -Property Extension Descending
  • anArray sort

19
???????? ????????? ???????
  • Foreach-object
  • dir foreach-object _.Name
  • Alias dir _.Name
  • Where-object
  • dir where-object _.Length gt 10
  • Alias dir ? _.Length gt 10
  • Select-object
  • dir select-object first 5
  • Alias none
  • Sort-Object, Group-Object...

20
?????????? ?? ?????
  • ???????????
  • ?????
  • Format-Custom
  • Format-List
  • Format-Table
  • Format-Wide
  • Out-Default
  • Out-Null
  • Out-Host
  • Out-Printer
  • Out-String
  • Out-File
  • Out-GridView

21
DEMO
  • Pipelines, loops, ?????????? ?? ?????

22
?????? ?? ???????
  • ????????? ?? .NET ?????????
  • System.Reflection.AssembyLoadFrom(my.dll)
  • Get-Member
  • ???? ?? ????????? ? ????????? ?? ??????? ??????
  • New-object
  • ???????? ?? ??? ??????
  • COM ??? .NET ??????
  • ?? ???????? ?????????????
  • someObject new-object System.ArrayList

23
Pseudo-Reflection
  • Get-Member
  • ????? ?? ??????, ??????? ? ????? ?????????
  • Add-Member
  • ???????? ?? ??????? ??? ??????
  • dir add-member -passthru -membertype
    scriptmethod -name MyMethod write-host File
    name "this.Name _.MyMethod()
  • ps1XML Files ???????????? ?? ?????????? ??????

24
DEMO
  • ?????? ?? ???????

25
???????? v2 ????????
  • Reading/Parsing
  • TXT, CSV, XML read/write
  • ??????????????
  • Import-CLIXML, Export-CLIXML
  • Hydration/Rehidration
  • ???? ? HashTables
  • ?????? ? ???????
  • ??????????

26
???????? v2 ???????? (2)
  • Threading
  • Start-PSJob
  • Stop-PSJob
  • Wait-PSJob
  • Receive-PSJob
  • Remoting
  • Enables Remote PowerShell calls to be performed
  • Implemented using the Threading commands
  • ??????????? ?? ???? ??? ???????? ??????????
    ?????? ?? ???????????? ???????????

27
????? ????????? cmdlet-?...
  • Add-Content
  • ???????? ?? ???????? ?? ????
  • Start-Service, Stop-Service
  • ?????? ?? Windows ???????
  • Select-String
  • ?????? ?? ?????????
  • Test-Path
  • ?????? ?? ???? ??????
  • Compare-Object
  • ??????????? ?? ???????
  • Measure-Command
  • ??????? ?? ????? ?? ?????????? ?? ???????
  • Read-Host, Write-Host
  • ????/????? ?? ??????? ?? ???? ????????????

28
DEMO
  • ???????? ????????

29
???????
  • http//PowerShellCommunity.org
  • http//halr9000.com
  • http//powerscripting.net
  • http//vmguru.com
  • http//blog.usepowershell.com
  • http//thepowershellguy.com/blogs/posh/

30
?
Write a Comment
User Comments (0)
About PowerShow.com