Windows Server 2008 (PowerShell Scripting Uygulamaları)

2,793 views

Published on

Windows Server 2008 (PowerShell Scripting Uygulamaları)

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,793
On SlideShare
0
From Embeds
0
Number of Embeds
121
Actions
Shares
0
Downloads
2
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Windows Server 2008 (PowerShell Scripting Uygulamaları)

  1. 1. { PowerShell Scripting Uygulamaları} Mesut ALADAĞ Teknoloji Direktörü / MCT mesutaladag@mayasoft.com.tr Sunumumuz 15:00’da başlayacaktır…
  2. 2. Ajanda • PowerShell Nedir? • PowerShell Kurulumu • PowerShell Giriş ve Özellikler • Temel Komutlar • Değişken ve Operatör Kullanımı • Döngüler ve Akış Kontrol Deyimleri • Genel Uygulamalar • PowerShell’in Geleceği
  3. 3. PowerShell Nedir?
  4. 4. • Before you install Windows PowerShell, be sure that your system has the software programs that Windows PowerShell requires. Windows PowerShell requires the following programs: • Windows XP Service Pack 2, Windows 2003 Service Pack 1, or later versions of Windows • Microsoft .NET Framework 2.0 • If any version of Windows PowerShell is already installed on the computer, use Add or Remove Programs in Control Panel to uninstall it before installing a new version. PowerShell Kurulumu-I
  5. 5. • Windows XP Service Pack 2, Windows 2003 Service Pack 1 – http://www.microsoft.com/windowsserver2003/t echnologies/management/powershell/download. mspx PowerShell Kurulumu-II
  6. 6. PowerShell Kurulumu-III
  7. 7. PowerShell Başlatılması
  8. 8. PowerShell Temel Özellikleri  İnterAktif Kabuk ve Script Programlama da bir devrim  .NET Tabanlı  Yerleşik yaklaşık (~130) komut  .NET’in avantajlarını kullanabilen yeni bir dil  “nesne-tabanlı” pipeline görünümü  Mevcut araçlara destek devam ediyor.  (COM, ADSI, WMI, ADO, XML, Text, …)  Otomatik Komut Tamamlama Özelliği
  9. 9. Merak Edilenler • Powershell Kullanmadan Önce .NET Öğrenmelimiyim? – Hayır. • Mevcut Kullandığım Script ve Araçları Yeniden mi Yazmam Gerekiyor? – Hayır • Öğrenmem gereken bir dil var mı? – Hayır. – Çoğu DOS & UNIX komutunu kullanabilirsiniz.
  10. 10. CMDLETS Verb Noun Command
  11. 11. MSH> get-mailbox –server “smbex01” Verb Noun Name Argument String Command Parameter Property Names Property Values Name Alias Server StorageQuota ---- ---- ------ ------------ Bob Kelly bobk smbex01 unlimited Kim Akers kima smbex01 unlimited Exchange 2007’den bir örnek
  12. 12. DEMO
  13. 13. PWShell İle Alias Kullanımı
  14. 14. PWShell İle Alias Kullanımı - II
  15. 15. PWShell İle Alias Kullanımı - III
  16. 16. DEMO
  17. 17. PowerShell ile PipeLine Kullanımı
  18. 18. DEMO
  19. 19. Windows PowerShell EngineWindows PowerShell Engine Custom ApplicationCustom Application Microsoft Management Console 3.0Microsoft Management Console 3.0 PSObjectPSObject Windows PowerShell CmdletsWindows PowerShell CmdletsCommandCommand LineLine GUIGUI MMC 3.0 Layered Over Windows PowerShell Layered OverLayered Over Windows FormsWindows Forms Early Bound ObjectsEarly Bound Objects YourYour ApplicationApplication To ManageTo Manage
  20. 20. PowerShell Engine Exchange cmdlets Configuration Data Access AD Registry Meta base MAPI Store Process boundary E2007Management ArchitectureE2007Management Architecture Early-bound objs WinForms ADO.Net PowerShell Data Provider WinForms CLI GUI Setup
  21. 21. • Exchange 2007 – Fully build on PowerShell, fully scriptable • Add new users, mailboxes, mailstores… – GUI has only a subset of features • GUI “records” actions and present the PowerShell script at the end • Virtual Machine Manager – Fully build on PowerShell, fully scriptable • Add new network cards, memory, processors… • System Center Operations Manager – Server features scriptable via PowerShell • Data Protection Manager v2 – Fully on PowerShell • System Center “Service Desk” – PowerShell support, percentage ? • Windows Server “Longhorn” – New Server Manager fully scriptable – Not on Server core! (no .net Framework!) • Windows Server Compute Clusterv2 • Part of Common Engineering Criteria – Version 2009 Microsoft Products using PowerShell
  22. 22. The command prompt knows how to handle • “hello world” • 2 + 3 = 5 • 2 + 3 + “4” = 9 • “4” + 2 = 42 • “hello” * 3 = hellohellohello Object oriented everywhere
  23. 23. Variable Use with PowerShell • You can use virtually any variable name you choose, names are not case sensitive. • But, there are illegal characters such as; ! @ # % & , . and spaces. PowerShell will throw an error if you use an illegal character. – Must start with $ – $a = 32 – Can be typed – [int]$a = 32 $Microsoft $MicroSoft $microsoft are The Same! ${My English Name is #merlin@} is OK!
  24. 24. Variable Type • Powershell variable type is base on .NET Framework. • Common variable is as below: – [adsi], [array], [bool], [byte], [char] – [datetime], [decimal], [double] – [int] or [int32], [long] – [single], [scriptblock], [string] – [WMI], [WMIclass], [xml]
  25. 25. Declaring Variables and Type Adaptation • $a=333 • $b=“66” • $c=SS $a.GetType() $b.GetType().Name $a+$b ; $b+$a ?? $b+$c ; $c+$b ?? $a+$c ; $c+$a ?? Capture User Input Use Read-Host to get user input $a = Read-Host “Enter your name” Write-Host "Hello" $a
  26. 26. All Variables are Object • [int]$Age=22 • $Age.GetType() • $Age GetType().Name • $Age | Get-Member • $Title=“manager” • $Title.length • $Title.CompareTo()
  27. 27. DEMO
  28. 28. Array • To initialise – $a = 1,2,4,8 • To query – $b = $a[3]
  29. 29. PowerShell ile Sürücüler ve Registry PSDrive
  30. 30. • VMI (Windows Management Instrumentation) • PowerShell ortamından VMI Scriptlerini de çalıştırabiliyoruz. PowerShell ile VMI Uygulamaları
  31. 31. Powershell Operator  Arithmetic Binary Operators  +, -, *, , %, ++, --  Assignment Operators  =, +=, -=, *=, /=, %=  Logical Operators  !, -not, -and, -or  String Operators  +, *, -f, -replace, -match, -like  Comparison Operators  -eq, -ne, -gt, –ge, -lt, –le
  32. 32. Arithmetic Binary Operators • 123+789 ; 222-876 • 34.5*44.2 ; 13/7 • 123%5 • $var++ ; ++$var  $var = $var + 1 • $var-- ; --$var  $var = $var – 1
  33. 33. Assignment Operators • $var=3 • $var+=3 ; $var-=3 • $var*=3 ;$var/=3 ; $var%=3 • $var = 0x10  echo $var  16 • $var = 7.56e3  echo $var  7560 • $var=7MB  echo $var  7340043 (bytes)
  34. 34. Logical Operators • (7 -eq 7) -and (2 -eq 5) • (7 -eq 7) -or (2 -eq 5) • (9 -eq 9) -xor (4 -eq 4) ; (9 -eq 9) -xor (4 -eq 7) • (3 -eq 3) -and !(2 -eq 2) • (3 -eq 3) -and -not (2 -eq 9)
  35. 35. String Operators -like ; -clike ; -ilike To be like as -notlike ; -cnotlike ;-inotlike To not be like as -match ; -cmatch ;-imatch Match -notmatch ; -cnotmatch ; -inotmatch Not match -contains ; -ccontains ; -icontains Include -notcontains; -cnotcontains ; -inotcontains Not include
  36. 36. Comparison Operators • -le ; -cle ; -ile  <= • -eq; -ceq; -ieq  = • -ne; -cne; -ine  != • -gt; -cgt; -igt  > • -ge; -cge; -ige  >= • -lt; -clt; -ilt  < • -le; -cle; ile  <=
  37. 37. Loop and Flow Control • If…. elseif… else… • Switch…… default • ForEach ( Foreach-Object ) • For • While • Do….. While • Do…..Until • Break & Continue
  38. 38. If…. elseif… else… $a = "white" if ($a -eq "red") {"The colour is red"} elseif ($a -eq "white") {"The colour is white"} else {"Another colour"}
  39. 39. Switch…… default Another method to run a specific set of code given specific conditions $a = "red" switch ($a) { "red" {"The colour is red"} "white"{"The colour is white"} default{"Another colour"} }
  40. 40. ForEach ( Foreach-Object ) Loop through a collection of objects Foreach ($i in Get-Childitem c:windows) {$i.name; $i.creationtime}
  41. 41. For Repeat the same steps a specific number of times For ($a=1; $a –le 10; $a++) {$a}
  42. 42. While, do while, do until Do While Loop Can repeat a set of commands while a condition is met $a=1 Do {$a; $a++} While ($a –lt 10) Do Until Loop Can repeat a set of commands until a condition is met $a=1 Do {$a; $a++} Until ($a –gt 10)
  43. 43. Break; Continue • For ($i = 1; $i -le 10; $i++) { Write-Host $i If ($i -eq 5) { Write-Host "BREAK!!“ Break } } • ForEach ($i in 1..10) { If ($i % 2) { Continue } $i }
  44. 44. Reduced Complexity
  45. 45. DEMO
  46. 46. • [void] [reflection.assembly]::LoadWithPartialName("System.Windows.Forms") • $form = new-object Windows.Forms.Form • $form.Text = "My First Form" • $button = new-object Windows.Forms.Button • $button.text=“Çözümpark Tıklayın!" • $button.Dock="fill" • $button.add_click({$form.close()}) • $form.controls.add($button) • $form.Add_Shown({$form.Activate()}) • $form.ShowDialog() Form Uygulaması - Hello World
  47. 47. • PS1 – Windows PowerShell shell script powershell.exe –noexit &”c:myscript.ps1” • PS1XML – Windows PowerShell format and type definitions • PSC1 – Windows PowerShell console file • PSD1 – Windows PowerShell data file • PSM1 – Windows PowerShell module file File extensions
  48. 48. • http://blogs.msdn.com/powershell/attachme nt/1561580.ashx PowerShell Cheat Sheet
  49. 49. • Microsoft is working on the next version of PowerShell • Installed by default on Windows Server 2008 R2 and Windows 7 • http://www.microsoft.com/downloads/details .aspx?FamilyID=60deac2b-975b-41e6-9fa0- c2fd6aa6bc89&displaylang=en PowerShell 2.0
  50. 50. • PowerShell Remoting • Background Jobs • Transactions • ScriptCmdlets • Modules • Script Debugging • Eventing • Windows PowerShell Integrated Scripting Environment • Network File Transfer • New Cmdlets • New Operators • Exception Handling with Try-Catch-Finally PowerShell 2.0 Neler Getiriyor?
  51. 51. Daha Fazla Bilgi İçin – Microsoft Press – Microsoft Windows PowerShell Step By Step – Manning – Windows PowerShell in Action – Sams – Windows PowerShell Unleashed – Sapien Press – Microsoft Windows PowerShell – TechNet - Scripting with Windows PowerShell – www.cozumpark.com – http://blogs.msdn.com/powershell.
  52. 52. Sorularınız ?
  53. 53. Teşekkürler www.cozumpark.com | www.mesutaladag.com Mesut ALADAĞ Teknoloji Direktörü / MCT mesutaladag@mayasoft.com.tr

×