1 / 19

Windows PowerShell

Windows PowerShell. Mi a PowerShell?. Új Windows parancssor, melyet rendszer-adminisztrátorok számára terveztek. Ingyenes. A .NET FrameWork 2.0-s verzióján alapul. Objektum-orientált. Első találkozás. Indítása. Case Insensitive. Előző, következő sor szerkesztése.

parker
Télécharger la présentation

Windows PowerShell

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Windows PowerShell

  2. Mi a PowerShell? • Új Windows parancssor, melyet rendszer-adminisztrátorok számára terveztek. • Ingyenes. • A .NET FrameWork 2.0-s verzióján alapul. • Objektum-orientált.

  3. Első találkozás • Indítása. • Case Insensitive. • Előző, következő sor szerkesztése. • Tab, Shift-Tab használata, • Vágólap használata.

  4. Cmdlet • A korábbi shellekben megszokott parancsok neve cmdlet. • Cls • Get-Help • Get-Help * • Get-Help s* • Get-Help *q* • Get-help foreach • Get-Help foreach -detail

  5. Kimenet, konverziók • Get-Help >\Help.txt • Get-Help | Out-File C:\Help2.txt • Get-Help | Export-Csv C:\Csv1.csv • Get-Help | Export-CliXML C:\Xml1.xml • Get-Service | ConvertTo-Html >C:\html1.html

  6. Write-Host • Egyszerű kiíró cmdlet. • Write-Host „Vörös és Fekete” –foregroundcolor black –backgroundcolor red

  7. Get-Process • A futó processzek listázása • Get-Process explorer • Get-Process explorer | format-list PS C:\pws> get-process Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 269 13 96948 83808 260 90,00 2300 AcroRd32 116 6 1600 4056 36 0,08 1096 alg 93 3 840 3228 23 0,53 944 ati2evxx 103 3 992 3504 28 1,77 1320 ati2evxx 68 3 860 3340 30 0,31 2612 ctfmon 782 7 2656 6120 28 35,69 692 csrss

  8. Get-Service • A háttérfolyamatok megjelenítésére szolgál PS C:\pws> get-service Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 269 13 96948 83808 260 90,00 2300 AcroRd32 116 6 1600 4056 36 0,08 1096 alg 93 3 840 3228 23 0,53 944 ati2evxx 103 3 992 3504 28 1,77 1320 ati2evxx 68 3 860 3340 30 0,31 2612 ctfmon 782 7 2656 6120 28 35,69 692 csrss

  9. Sort-Object • Az objektumok rendezésére szolgál • Get-Process | Sort-Object ProcessName • Get-Process | Sort-Object CPU –descending

  10. Where-Object • A bementen megjelenő objektumok szűrése • -eq, -ne, -gt, -ge, -lt, -le, -like stb. PS C:\pws> Get-Process | Where-Object { $_.Processname -eq "explorer" } Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 830 21 24084 32660 136 119,45 1480 explorer PS C:\pws> Get-Process | Where-Object { $_.CPU -gt 10 } Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName ------- ------ ----- ----- ----- ------ -- ----------- 269 13 95512 82432 260 93,05 2300 AcroRd32 771 7 2652 6192 29 38,25 692 csrss 830 21 24084 32660 136 119,58 1480 explorer 281 11 35384 46276 124 23,73 2688 firefox 634 19 21448 35964 117 13,00 2968 iexplore Hivatkozás egy tulajdonságra

  11. Select-Object • Meghatározott tulajdonságok kiválasztása PS C:\pws> Get-Process | Select-Object ProcessName, CPU ProcessName CPU ----------- --- AcroRd32 93,046875 alg 0,078125 ati2evxx 0,53125 ati2evxx 2,0625 ctfmon 0,328125 csrss 39,53125 PS C:\pws> Get-Process | Select-Object ProcessName, CPU -first 3 ProcessName CPU ----------- --- AcroRd32 93,046875 alg 0,078125 ati2evxx 0,53125

  12. ForEach-Object • Az bemenet objektumainak egyenkénti feldolgozása PS C:\pws> Get-Process | Select-Object ProcessName, CPU | ForEach-Object { Write-host $_.ProcessName } AcroRd32 alg ati2evxx ati2evxx ctfmon csrss devldr32 explorer firefox hpgs2wnd

  13. Elágazás: if – elif – else • A megszokott szintaxissal. PS C:\pws> Get-Process | Select-Object ProcessName, CPU | ForEach-Object { if ( $_.ProcessName -eq "explorer") { Write-host $_.CPU $_.ProcessName } } 120,234375 explorer

  14. Változók • A változók $ jellel kezdődnek. • $a=„Alma” (+,*) • $c=3; (+,-,*,/,%) • $a – replace „A”,”B” PS C:\pws>$szin=„blue” ; Write-Host –foregroundcolor $szin „Hello” Hello

  15. Futtatás • A szkriptek kiterjesztése ps1 • Futtatása a név begépelésével történik. • Policy: Get-ExecutionPolicy, Set-ExecutionPolicy Services.ps1: Get-Service | ForEach-Object { if ( $_.Status -eq "Running" ) { $szin="red" } else { $szin="green" } write-host -foreground $szin $_.DisplayName }

  16. EventLog • Get-Eventlog –List • Get-Eventlog system • Get-Eventlog system –newest 1 • Get-Eventlog system –newest 1 | format-list Get-EventLog System | ForEach-object { if ( $_.Source -eq "Windows Update Agent" ) { Write-Host $_.Message } }

  17. Gyakorlatban • Jelenítsük meg a háttérfolyamatok listáját a böngészőben! Get-Service | ConvertTo-Html -Property Status,DisplayName | ForEach-Object { Write-Host $_ if ( $_ -like "*<td>Running</td>*" ) { $_ -replace "<tr>", "<tr bgcolor='RED'>„ } else { $_ -replace "<tr>", "<tr bgcolor='GREEN'>„ } } | Out-File C:\processes.html

  18. Fájlrendszer • Get-psdrive • Dir, Cd (alias példa) • New-Item • Remove-Item

  19. PSDrive • New-Psdrive –name FK –psprovider FileSystem –root c:\temp • Cd FK: • Remove-PsDrive FK

More Related