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
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. • Windows XP Service Pack 2, Windows 2003
Service Pack 1
– http://www.microsoft.com/windowsserver2003/t
echnologies/management/powershell/download.
mspx
PowerShell Kurulumu-II
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. 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.
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
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. 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. • 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
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. 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. 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
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
37. Loop and Flow Control
• If…. elseif… else…
• Switch…… default
• ForEach ( Foreach-Object )
• For
• While
• Do….. While
• Do…..Until
• Break & Continue
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. 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. ForEach ( Foreach-Object )
Loop through a collection of objects
Foreach ($i in Get-Childitem c:windows)
{$i.name; $i.creationtime}
41. For
Repeat the same steps a specific number of
times
For ($a=1; $a –le 10; $a++)
{$a}
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. 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 }
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. • 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
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. • 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. 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.