¿ù°£ Àα⠰Խù°

°Ô½Ã¹° 58°Ç
   
[POWERSHELL] PowerShell¿¡¼­ Sort, Measure, Select, Filter »ç¿ëÇϱâ
±Û¾´ÀÌ : ÃÖ°í°ü¸®ÀÚ ³¯Â¥ : 2013-01-02 (¼ö) 12:31 Á¶È¸ : 4628
±ÛÁÖ¼Ò :
                          

Ãâó : http://bloglee.egloos.com/4868394

1) Á¤·ÄÇϱâ (Sort-Object)
SortingÇÒ ¶§ÀÇ ±âÁØÀº ÇØ´ç Cmdlets(Get-Process, Get-Service etc.)ÀÇ Property°¡ ¾î¶² °ÍÀÌ ÀÖ´ÂÁö ¸ÕÀú È®ÀÎÇÑ ÈÄ ±× Property¸¦ ±âÁØÀ¸·Î SortingÇÑ´Ù´Â °ÍÀ» À¯³äÇÑ´Ù.
(Âü°í: http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/sort-object.mspx)

ƯÁ¤ÇÑ cmdlet¿¡ »ç¿ëÇÒ ¼ö ÀÖ´Â Property ¹× Method¸¦ È®ÀÎÇÏ´Â ¸í·É¾î´Â Get-Member (In short, GM)ÀÌ´Ù.
Sort-Object°¡ ¹«¾ùÀÎÁö È®ÀÎÇÏ·Á¸é Get-Help Sort-Object¸¦ »ç¿ëÇÏ¿© µµ¿ò¸»À» º¸¸é µÈ´Ù

- Get-Process  (ÇöÀç ½ÇÇàÁßÀÎ ÇÁ·Î¼¼½º È®ÀÎ)
get-process | get-member  (get-processÀÇ Property ¹× Method º¸±â)
  (in short, ps | gm )
  ¿©±â¼­ VirtualMemorySize¶ó´Â Property°¡ Àִµ¥ ÀÌ°ÍÀÇ ¾à¾î´Â vmÀÌ´Ù. 
- get-process | sort-object vm  (get-processÀÇ °á°úÁß¿¡¼­ vmÀ̶ó´Â Property¸¦ ±âÁØÀ¸·Î ¿À¸§Â÷¼øÀ¸·Î Á¤·Ä)
  (In short, ps | sort vm )
- get-process | sort-object vm -descending (VM Ç׸ñ¿¡ ´ëÇÏ¿© ³»¸²Â÷¼øÀ¸·Î Á¤·Ä)
  (In Short, ps | sort vm -desc)
- get-process | sort-object name, vm (name´ë·Î ¸ÕÀú ¿À¸§Â÷¼øÀ¸·Î Á¤·ÄÇÑ ÈÄ µ¿ÀÏÇÑ name¿¡ ´ëÇÏ¿© vmÀ¸·Î Á¤·Ä)
  ** svchostÀÇ ¼±ÅÃÇÏ¿© vmÀÌ ¿À¸§Â÷¼øÀ¸·Î Á¤·ÄµÇ¾î ÀÖ´ÂÁö È®ÀÎÇØ ºÁ¶ó.
- get-service | sort-object status  (À©µµ ¼­ºñ½ºÁß¿¡¼­ Status¶ó´Â Property¿¡ ´ëÇÏ¿© ¿À¸§Â÷¼øÀ¸·Î Á¤·ÄÇÑ °Í, ÀÌ·¸°Ô Çϸé Running, Stopped µÈ °ÍÀ» È®ÀÎÇÒ ¼ö ÀÖ´Ù)
  (In Short, gsv | sort status)

2) Åë°è È®ÀÎÇϱâ (Measure-Object)
ƯÁ¤ÇÑ Object¿¡ ´ëÇÑ count, average, sum, minimum, maximum °ªÀ» È®ÀÎÇÑ´Ù
(Âü°í: http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/measure-object.mspx)

- Help Measure-Object
- Help Measure-Object -Example
- Get-Service
- Get-Service | Measture-Object  (Property¸¦ ¿É¼ÇÀ¸·Î ÁöÁ¤ÇÏÁö ¾Ê°í ½ÇÇàÇÏ¿´À¸¸ç, ¼­ºñ½ºÀÇ ¼ö·®¸¸ È®ÀεÊ)
- Get-Process  (ÇöÀç ½ÇÇàÁßÀÎ ÇÁ·Î¼¼½º È®ÀÎ)
- Get-Process | Measure-Object  (Property¸¦ ¿É¼ÇÀ¸·Î ÁöÁ¤ÇÏÁö ¾Ê°í ½ÇÇàÇÏ¿´À¸¸ç, ÇöÀç ½ÇÇàÁßÀÎ ¼­ºñ½ºÀÇ ¼ö·®¸¸ È®ÀεÊ)
- Get-Process | Get-Member  (Get-Process¿¡¼­ »ç¿ëÇÒ ¼ö ÀÖ´Â Property È®ÀÎ)
- Get-Process | Measure-Object -Property PM -min -max -average -sum  (ÇÁ·Î¼¼½º ¼ö·® ¹× PagedMemorySizeÀÇ ÃÖ¼Ò, ÃÖ´ë, Æò±Õ, Çհ踦 È®ÀÎ)
- Get-Process | Measure-Object -Property VM -min -max -average -sum (VirtualMemorySize ³»¿ë È®ÀÎ)
- Get-Process | Measure-Object -Property WorkingSet -min -max -average -sum (WorkingSet ³»¿ë È®ÀÎ)
- Get-Service | Get-Member
- Get-Service | Measure-Object -Property DisplayName -line -word -character

3) ¿øÇÏ´Â °Í¸¸ ¼±ÅÃÇϱâ (Select-Object)
±âº» Property°¡ ¾Æ´Ñ ¿øÇÏ´Â Property¸¸ È­¸é¿¡ µð½ºÇ÷¹ÀÌÇϱâ
¶Ç´Â Á¤·ÄµÈ Ä÷º¼ÇÀÇ Ã³À½(³¡)¿¡¼­ ¼±ÅÃµÈ Object ¼ö·®À» »Ì¾Æ³»´Â °Í 
(Âü°í: http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/select-object.mspx)
- Help Select-Object
- Help Select-Object -example
- Get-Service  (Status, Name, DisplayNameÀ» ±âº»ÀûÀ¸·Î È­¸é¿¡ µð½ºÇ÷¹ÀÌÇÑ´Ù)
- Get-Service | Get-Member  (¾î¶² Property°¡ ÀÖ´ÂÁö È®ÀÎ)
   (In Short, gsv | gm)
- Get-Service | Select-Object DisplayName, DependentServices
- Get-Process | Select-Object -First 10  (ÇÁ·Î¼¼½º À̸§À¸·Î Á¤·ÄµÈ °Í¿¡¼­ À§¿¡¼­ 10¹ø° °Í ±îÁö¸¸ È®ÀÎÇϱâ)
Get-Process | Select -Last 10  (Select-Object¸¦ ÁÙ¿©¼­ Select¸¸ »ç¿ë / ¾Æ·¡¿¡¼­ 10¹ø° °Í ±îÁö¸¸ È®ÀÎ)
- Get-Process | Sort-Object VM -Desc | Select-Object -First 10  (VM Ç׸ñÀ» ³»¸²Â÷¼øÀ¸·Î Á¤·ÄÇÏ¿© À§¿¡¼­ 10¹ø°±îÁö È®ÀÎ)
- Get-Process | Sort-Object VM -Desc | Select-Object -First 10  | Out-File c:\top_vm_users.txt  (°á°ú¸¦ ÆÄÀÏ·Î ÀúÀå)

4) °á°ú¿¡ ´ëÇÑ ÇÊÅ͸µÇϱâ (Where-Object)
cmdlet¿¡ ÀÇÇÑ °á°ú Áß¿¡¼­ ƯÁ¤ÇÑ Property¸¦ ±âÁØÀ¸·Î ¿øÇÏ´Â °Í°ú ÇÊÅ͸µÇÏ¿© °á°ú¸¦ º»´Ù
Çü½Ä: Cmdlet | Where-Object {$_.Property ¿¬»êÀÚ ¼ýÀÚ/¹®ÀÚ}
(Âü°í: http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/where-object.mspx)

-lt -- Less than  (< )

-le -- Less than or equal to (<= )

-gt -- Greater than ( > )

-ge -- Greater than or equal to ( >= )

-eq -- Equal to ( = )

-ne -- Not equal to ( <> )

-like – Like; uses wildcards for pattern matching


- Help Where-Object
- Help Where-Object -Example
- Get-Service | Where-Object {$_.Status -eq "Running"}   (RunningÀÎ ¼­ºñ½º¸¸ ÇÊÅ͸µÇÏ¿© º¸¿©ÁÖ±â)
- Get-Service | Where-Object {$_.Status -eq "Running"}  | Sort-Object DisplayName 
- Get-Service | Where-Object {$_.Status -eq "Running"}  | Sort name -Desc  (Sort¸¦ ÁÙ¿©¼­ »ç¿ë)
- Get-Service | Where-Object {$_.Status -eq "Running"}  | Sort-Object name | Select-Object -First 10
  (RunningÁßÀÎ ¼­ºñ½º¸¦ NameÀ» ±âÁØÀ¸·Î ¿À¸§Â÷¼øÀ¸·Î Á¤·ÄÇÑ °Í Áß¿¡¼­ À§¿¡¼­ 10¹ø° ±îÁö¸¸ È®ÀÎÇϱâ)

- Get-Process  (¿©±â¼­ PowerShellÀÌ ¾ó¸¶ÀÇ VM (´ÜÀ§ MB)À» »ç¿ëÇÏ´ÂÁö È®ÀÎÇÑ´Ù)
- Get-Process | Select-Object VM, Name  (VM¿¡ ´ëÇÏ¿© »ó¼¼ÇÑ ¼ýÀÚ°¡ ³ª¿À´Â °ÍÀ» ¾Ë ¼ö ÀÖ´Ù. ´ÜÀ§ Byte)
- Get-Process | Where-Object {$_.VM -gt 100}  (100 byte ÀÌ»óÀÇ VMÀ» »ç¿ëÇÏ´Â ÇÁ·Î¼¼½º È®ÀÎ)
- 1kb
- 1mb
- 1gb
- 1mb + 1gb
- Get-Process | Where-Object {$_.VM -gt 100mb} (100 MB ÀÌ»óÀÇ VMÀ» »ç¿ëÇÏ´Â ÇÁ·Î¼¼½º È®ÀÎ)
- Get-Process | Sort-Object PM -Desc | Select-Object -First 1 | Stop-Process -WhatIf
  (In short, PS | Sort pm -desc | Select -first 1 | kill -whatif)
  (PMÀ» °¡Àå ¸¹ÀÌ »ç¿ëÇÏ´Â ÇÁ·Î¼¼½º¸¦ Á¾·áÇÒ±î?)
- Get-Service | Where-Object {$_.Status -eq "Stopped"}  | Set-Service -StartupType Disabled -WhatIf
  (StoppedÁßÀÎ ¼­ºñ½ºÀÇ ½ÃÀÛÀ¯ÇüÀ» Disabled·Î ¼³Á¤ÇÏ¸é ¾î¶³±î?)



À̸§ Æнº¿öµå
ºñ¹Ð±Û (üũÇÏ¸é ±Û¾´À̸¸ ³»¿ëÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.)
¿ÞÂÊÀÇ ±ÛÀÚ¸¦ ÀÔ·ÂÇϼ¼¿ä.
   

 



 
»çÀÌÆ®¸í : ¸ðÁö¸®³× | ´ëÇ¥ : ÀÌ°æÇö | °³ÀÎÄ¿¹Â´ÏƼ : ·©Å°´åÄÄ ¿î¿µÃ¼Á¦(OS) | °æ±âµµ ¼º³²½Ã ºÐ´ç±¸ | ÀüÀÚ¿ìÆí : mojily°ñ¹ðÀÌchonnom.com Copyright ¨Ï www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.