참고 :
http://umttumt.org/107 http://blog.naver.com/yjsaga?Redirect=Log&logNo=80094183249
Windows PowerShell은 시스템 관리자를 위해 특별히 디자인된 새로운 Windows 명령줄 셸로써, 조합하거나 독립적으로 사용할수 있는 대화형 프롬프트 및 스크립트 환경이 포함되어있다.
Windows Server를 관리하다보면, 리눅스와 달리 Shell 스크립트 제작에 불편함이 있다.
cmd로 기본적인 기능들의 구현은 가능하지만, 복잡한 작업을 하기에는 무리가 있다.
이를 극복하기 위해 Windows PowerShell이 나왔으며, Windows 2008 Server에서는 기본으로 체택하고 있다.
Windows PowerShell 1.0을 통하여 보다 많은 작업들이 가능해졌으며, Windows PowerShell 1.0은 WIndows Server 2003 에서도 사용 가능했었으나, 3rd Party의 느낌이었다.
하지만 Windows 2008 Server 에서는 WIndows PowerShell 1.0을 기본으로 체택함과 동시에, 현재는 WIndows PowerShell 2.0이 발표 되었고, 보다 많은 기능들의 개선이 있었다.
또한 무엇보다 가장 큰 이점은 이미 익숙한 도구를 계속 사용할 수 있다는 점입니다. 즉, Net, SC 및 Reg.exe와 같은 기존 Windows 도구를 Windows PowerShell에서 그대로 사용할 수 있습니다. 레지스트리, 작업관리자 등 윈도우의 모든 부분을 직접 컨트롤 할 수 있기 때문에 관련 분들은 자주 사용되는 툴이 될 것으로 보입니다.
윈도우의 경우 그래픽을 사용한 UI가 강화되어 있는 것이 특징입니다. 그러나 명령어를 해석하는 프로그램인 shell과 같은 경우에는 text UI가 속도 면에서 우월합니다. 이런면을 타OS 비해 보충하기 위하여 만들어진 것이 Windows PowerShell 이죠... (CMD.exe 역시 셸의 일종이지만서도...)
통합 개발 환경(Integrated Development Environment, IDE)이라는 것은 개발자에게 일관된 인터페이스를 제공을 해서 코딩, 컴파일, 디버깅 등 개발에 편이성을 제공하는 소프트웨어적인 도구이다. 같은 맥락으로 파워셸(PowerShell)에서도 통합 스크립팅 환경(Integrated scripting Environment)이 라는 약칭 ISE가 Windows 7에 탑재 되었습니다. 즉, Windows PowerShell ISE(통합 스크립팅 환경)는 친숙한 환경에서 스크립트 및 모듈을 작성, 실행 및 테스트할 수 있는 호스트 응용 프로그램입니다. 구문 색 지정, 탭 완성, 시각적 디버깅, 유니코드 규정 준수 및 상황에 맞는 도움말과 같은 주요 기능을 통해 풍부한 스크립팅 환경을 제공합니다.
Windows Server 2003용 PowerShell 1.0 :
http://www.microsoft.com/downloads/details.aspx?FamilyID=c61fb27b-e71c-4ecf-9d2c-9b299b149490&DisplayLang=ko
Windows PowerShell 2.0 :
http://www.microsoft.com/downloads/details.aspx?FamilyID=c913aeab-d7b4-4bb1-a958-ee6d7fe307bc&DisplayLang=en
시작방법
실행
몇가지 예제들....
PS C:\Users\Administrator> get-help
PowerShell cmd 의 개념에 대한 도움말 표시
PS C:\Users\Administrator> get-help get-date
이름
Get-Date
개요
현재 날짜 및 시간을 가져옵니다.
구문
Get-Date [[-date] <DateTime>] [-displayHint {<Date> | <Time> | <DateTime>}] [-format <string>] [-year <int>] [-mont
h <int>] [-day <int>] [-hour <int>] [-minute <int>] [-second <int>] [<CommonParameters>]
Get-Date [[-date] <DateTime>] [-displayHint {<Date> | <Time> | <DateTime>}] [-uFormat <string>] [-year <int>] [-mon
th <int>] [-day <int>] [-hour <int>] [-minute <int>] [-second <int>] [<CommonParameters>]
자세한 설명
현재 날짜 및 시간을 가져옵니다.
관련 링크
Set-Date
New-TimeSpan
설명
자세한 내용을 보려면 다음과 같이 입력하십시오. "get-help Get-Date -detailed".
기술적인 내용을 보려면 다음과 같이 입력하십시오. "get-help Get-Date -full".
기존 cmd의 echo와 같은 Write-Host. cmd의 명령들도 그대로 사용할 수 있다.
PS C:\Users\Administrator> Write-host "HELLO, MOJILY"
HELLO, MOJILY
PS C:\Users\Administrator> echo "HELLO, MOJILY"
HELLO, MOJILY
시간 표시
PS C:\Users\Administrator> date
2009년 12월 29일 화요일 오전 9:21:56
PS C:\Users\Administrator> get-date
2009년 12월 29일 화요일 오전 9:22:02
시간 가지고 놀기
PS C:\Users\Administrator> [datetime]
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True DateTime System.ValueType
PS C:\Users\Administrator> [datetime]::now
2009년 12월 29일 화요일 오전 9:23:09
PS C:\Users\Administrator> [datetime]::now.tostring()
2009-12-29 오전 9:23:16
PS C:\Users\Administrator> [datetime]::now.addhours(-1)
2009년 12월 29일 화요일 오전 8:23:34
PS C:\Users\Administrator> [datetime]::now.addhours(1).tostring()
2009-12-29 오전 10:33:08
변수 및 시간 포맷 바꾸기
PS C:\Users\Administrator> $a=1
PS C:\Users\Administrator> write-host $a
1
PS C:\Users\Administrator> $b=3
PS C:\Users\Administrator> write-host $b
3
PS C:\Users\Administrator> $c=$a*$b
PS C:\Users\Administrator> write-host $c
3
PS C:\Users\Administrator> $date=[datetime]::now.addhours(-2)
PS C:\Users\Administrator> $date=get-date $date -uformat "%y+%m+%d+%H"
PS C:\Users\Administrator> write-host $date
09+12+28+09
get-command 명령
PS C:\Users\Administrator> get-command wscript
CommandType Name Definition
----------- ---- ----------
Application wscript.exe C:\Windows\system32\wscript.exe
PS C:\Users\Administrator> get-command *.msc
CommandType Name Definition
----------- ---- ----------
Application azman.msc C:\Windows\system32\azman.msc
Application certmgr.msc C:\Windows\system32\certmgr.msc
Application comexp.msc C:\Windows\system32\comexp.msc
Application compmgmt.msc C:\Windows\system32\compmgmt.msc
Application devmgmt.msc C:\Windows\system32\devmgmt.msc
Application diskmgmt.msc C:\Windows\system32\diskmgmt.msc
Application eventvwr.msc C:\Windows\system32\eventvwr.msc
Application fsmgmt.msc C:\Windows\system32\fsmgmt.msc
Application fsrm.msc C:\Windows\system32\fsrm.msc
Application gpedit.msc C:\Windows\system32\gpedit.msc
Application gpmc.msc C:\Windows\system32\gpmc.msc
Application gpme.msc C:\Windows\system32\gpme.msc
Application gptedit.msc C:\Windows\system32\gptedit.msc
Application lusrmgr.msc C:\Windows\system32\lusrmgr.msc
Application NAPCLCFG.MSC C:\Windows\system32\NAPCLCFG.MSC
Application perfmon.msc C:\Windows\system32\perfmon.msc
Application rsop.msc C:\Windows\system32\rsop.msc
Application secpol.msc C:\Windows\system32\secpol.msc
Application ServerManager.msc C:\Windows\system32\ServerManager.msc
Application services.msc C:\Windows\system32\services.msc
Application StorExpl.msc C:\Windows\system32\StorExpl.msc
Application tapimgmt.msc C:\Windows\system32\tapimgmt.msc
Application taskschd.msc C:\Windows\system32\taskschd.msc
Application tpm.msc C:\Windows\system32\tpm.msc
Application tsadmin.msc C:\Windows\system32\tsadmin.msc
Application tsconfig.msc C:\Windows\system32\tsconfig.msc
Application tsmmc.msc C:\Windows\system32\tsmmc.msc
Application wbadmin.msc C:\Windows\system32\wbadmin.msc
Application WF.msc C:\Windows\system32\WF.msc
Application WmiMgmt.msc C:\Windows\system32\WmiMgmt.msc
Application WSRM.msc C:\Windows\system32\WSRM.msc
get-process 명령
PS C:\Users\Administrator> get-process
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
260 8 4884 12244 76 0.50 12808 atbsvc
63 3 1380 3596 56 0.05 3884 conime
64 3 1360 4520 50 0.19 43576 conime
596 6 2552 4852 109 3.09 532 csrss
84 5 1552 5048 143 0.44 576 csrss
368 5 3256 12848 147 5.91 2716 csrss
352 5 5932 15856 163 2.27 42188 csrss
154 5 6384 8332 70 0.94 43280 daemon
63 2 872 2948 34 0.02 1888 dwm
101 3 2792 3904 49 0.33 3824 dwm
769 18 31656 45228 219 43.09 3060 explorer
497 13 18816 27128 138 2.88 30520 explorer
101 4 8140 8808 53 0.16 2700 iashost
0 0 0 24 0 0 Idle
517 15 16888 25244 145 0.73 14820 iexplore
387 12 11396 22036 135 0.72 43828 iexplore
328 32 15088 16548 87 16.00 1812 inetinfo
166 16 7296 12868 82 0.41 980 LogonUI
171 16 6808 13484 70 0.28 40052 LogonUI
940 13 6400 9784 57 114.02 672 lsass
310 4 3072 4764 36 0.70 680 lsm
710 26 96988 84564 366 1,603.23 1260 mmc
.......................................................................................
.......................................................................................
.......................................................................................
PS C:\Users\Administrator> get-process -inputobject $a |format-table -view priority
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
atbsvc 12808 259 12529664
conime 3884 63 3682304
conime 43576 64 4628480
csrss 532 592 4968448
csrss 576 84 5169152
csrss 2716 366 13156352
csrss 42188 354 16281600
PriorityClass: BelowNormal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
daemon 43280 154 8531968
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
dwm 1888 63 3018752
dwm 3824 101 3997696
explorer 3060 769 46313472
explorer 30520 497 27779072
iashost 2700 101 9019392
Idle 0 0 24576
iexplore 14820 517 25849856
iexplore 43828 387 22564864
inetinfo 1812 328 16945152
PriorityClass: High
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
LogonUI 980 166 13176832
LogonUI 40052 171 13807616
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
lsass 672 943 9986048
lsm 680 310 4878336
mmc 1260 710 86593536
mmc 7924 210 9375744
mmc 41748 654 113229824
PriorityClass: BelowNormal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
MSASCui 2896 371 14110720
MSASCui 41756 341 6475776
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
msdtc 3540 173 5566464
PriorityClass: BelowNormal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
msnmsgr 25908 529 3235840
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
msnmsgr 26132 554 5779456
mysqld-nt 1924 35200 12533760
NavvyMan 12428 246 4816896
PriorityClass: BelowNormal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
NavvyMan 30448 236 5754880
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
portforward 11084 11267 17285120
powershell 48856 445 44650496
rdpclip 796 160 6426624
rdpclip 41340 146 6729728
services 660 318 5992448
SLsvc 1108 107 7639040
smss 464 34 704512
snmp 480 194 5496832
spoolsv 1644 328 8400896
sqlwriter 328 89 5918720
svchost 272 131 3457024
svchost 348 83 2228224
svchost 568 241 3637248
svchost 836 325 6086656
svchost 844 126 6164480
svchost 896 395 7254016
svchost 936 418 42987520
svchost 1036 557 27467776
svchost 1068 171 5668864
svchost 1092 1731 61399040
svchost 1152 421 9777152
svchost 1220 435 15904768
svchost 1228 101 3702784
svchost 1240 90 3006464
svchost 1292 780 14237696
svchost 1408 280 7335936
svchost 1452 100 3162112
svchost 1752 137 7565312
System 4 794 1425408
taskeng 2040 279 6795264
PriorityClass: BelowNormal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
taskeng 2248 147 5062656
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
taskeng 33492 272 8663040
TCPSVCS 372 85 2916352
TrustedInstaller 48184 121 6123520
vmicsvc 1668 101 3813376
vmicsvc 1684 83 2457600
vmicsvc 1700 83 2535424
vmicsvc 1716 97 2523136
vmicsvc 1732 98 2551808
PriorityClass: High
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
wininit 584 113 2637824
winlogon 620 115 2539520
winlogon 1372 147 3964928
winlogon 46324 128 4984832
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
WmiPrvSE 2884 245 11276288
WMServer 1480 392 9416704
PriorityClass: High
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
wsrm 2052 411 11849728
PriorityClass: Normal
ProcessName Id HandleCount WorkingSet
----------- -- ----------- ----------
wuauclt 49128 93 5386240