2013년 1월 8일 화요일
Powershell Shortcuts
2013년 1월 4일 금요일
레지스트리읽기와 쓰기.
HKEY_CURRENT_USER : cd HKCU:
레스스트리 읽기, 쓰기
PS > Get-ItemProperty 키이름
PS > Set_ItemProperty 위치 -name 키이름 -value 키값
exe 실행하기
레지스트리 조작 부팅시 start-up 프로그램 지정
#
# 부팅시 Install2를 자동으로 실행한다.
#
#################################################################
param
(
[string]$ParamOption
)
Function StartUpInstall
{
param([string]$ParamOption )
$RegStartUp= "HKLM\Software\Microsoft\Windows\CurrentVersion\Run"
if ($ParamOption -eq "/u")
{
Remove-ItemProperty $RegStartUp -Name Install
}
else
{
Set-ItemProperty $RegStartUp -Name Install -Value c:\setup\install2.bat
}
}
StartUPInstall $ParamOption
Powershell 에서 XML Encoding 관련.
echo $XmlContent.configuration.'system.serviceModel'.services.service.endpoint.address
$XmlContent.configuration.'system.serviceModel'.services.service.endpoint.address = "net.tcp://172.16.10.99:20000/MessageService.svc"
$xmlContent.Save("c:\web.config")
Powershell 관련 Site
http://www.blkmtn.org/powershell-a-simple-menu
dictionary 사용
http://devcentral.f5.com/weblogs/Joe/archive/2008/12/29/powershell-abcs---g-is-for-generics.aspx
http://blogs.technet.com/b/heyscriptingguy/rss.aspx
1) http://get-scripting.blogspot.com/ (이것은 iTunes에서 Podcast로 제공하기도 한다;get-scripting)
powershel l관련 community.
http://powershellcommunity.org
http://www.cbtnuggets.com/webapp/product?id=456
K Alliance: Windows PowerShell Training Courses
http://www.kalliance.com/microsoft-it/windows-powershell.htm
KOENIG: PowerShell for Windows Server 2008
http://www.koenig-solutions.com/training/Powershell_admin2008.asp?gclid=COy62pzC6JoCFQQ9ZgodHzZ2CA
Course 10325: Five days; Instructor led. Covers V2.
Official MOC
http://www.microsoft.com/learning/en/us/Course.aspx?ID=10325a
Course 6434: Three days; Instructor-Led. Covers V1 only.
Official MOC
http://www.microsoft.com/learning/en/us/syllabi/6434afinal.mspx
Microsoft: Windows PowerShell for Administrators
Course 50025A: Three days; Instructor-Led. Covers V1 only.
Courseware Library
http://www.microsoft.com/learning/en/us/syllabi/50025afinal.mspx
PS Partnership
Custom PowerShell V1 and V2 Training on your site - world wide!
Contact: DoctorDNS@Gmail.Com
http://www.scriptinganswers.com/Training.asp
The SANS Institute PowerShell Training COurse
http://www.windowspowershelltraining.com/
TrainSiganl: Exchange Server 2007 PowerShell Course Outline
http://www.trainsignal.com/product_master_page_exchange_server_2007_powershell.aspx?ProductId=36
Verhoef Training: Windows PowerShell (UK)
http://www.verhoef-training.co.uk/outlines/WNPS.htm
http://www.winstructor.com/products/Windows-PowerShell-Training.html
Free Online Training
http://powershell.com/Mastering-PowerShell.pdf
http://www.manning.com/payette/
http://www.manning.com/payette2/ (in progress currently - MEAP)
http://www.sapienpress.com/powershell3.asp
http://www.primaltools.com/downloads/communitytools/ under the PowerShell TFM V1 ebook section.
http://oreilly.com/catalog/9780596528492/
http://oreilly.com/catalog/9780596521783/
http://www.microsoft.com/learning/en/us/book.aspx?ID=10329&locale=en-us
http://my.safaribooksonline.com/9780672329531?portal=samspublishing
http://www.microsoft.com/learning/en/us/Book.aspx?ID=12789&locale=en-us
http://www.microsoft.com/learning/en/us/book.aspx?ID=9541&locale=en-us
http://www.amazon.com/Windows-PowerShell-2-0-Best-Practices/dp/0735626464/ref=sr_1_11?ie=UTF8&s=books&qid=1261145411&sr=8-11
http://www.wrox.com/WileyCDA/WroxTitle/Professional-Windows-PowerShell.productCd-0471946931.html
Hosts and Providers:
http://www.wrox.com/WileyCDA/WroxTitle/Professional-Windows-PowerShell-Programming-Snapins-Cmdlets-Hosts-and-Providers.productCd-0470173939.html
http://www.manning.com/siddaway/ (in progress currently - MEAP)
http://www.apress.com/book/view/9781590599402
http://www.dummies.com/store/product/Windows-PowerShell-2-For-Dummies.productCd-0470371986.html
http://vig.pearsoned.com/store/product/1,1207,store-15080_isbn-0672329662,00.html
http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!6930.entry
(free ebook)
Windows PowerShell tips (Don Jones):
http://www.concentratedtech.com/upload/2/21powershelltips.pdf
www.concentratedtech.com/upload/2/21powershelltips.pdf
http://www.sapienpress.com/ad.asp
http://www.sapienpress.com/vmware.aspMicrosoft SQL Server 2008
http://www.wrox.com/WileyCDA/WroxTitle/Microsoft-SQL-Server-2008-Administration-with-Windows-PowerShell.productCd-0470477288.html
http://www.wrox.com/WileyCDA/WroxTitle/Professional-Windows-PowerShell-for-Exchange-Server-2007-Service-Pack-1.productCd-0470226447.html
www.wrox.com/WileyCDA/WroxTitle/Professional-Windows-PowerShell-for-Exchange-Server-2007-Service-Pack-1.productCd-0470226447.html
http://www.wrox.com/WileyCDA/WroxTitle/Scripting-SQL-Management-Objects-in-Windows-PowerShell.productCd-0470279354.html
Microsoft PowerShell, VBScript & JScript Bible:
http://eu.wiley.com/WileyCDA/WileyTitle/productCd-0470386800,descCd-description.html
eu.wiley.com/WileyCDA/WileyTitle/productCd-0470386800,descCd-description.html
2011년 5월 30일 월요일
[Powershell] 특정한 파일을 검색하여 그 파일 모두를 삭제하기
로컬 및 원격 컴퓨터의 특정한 파일을 검색하여 그 파일 모두를 삭제하고자 한다.
1) 특정한 폴더의 파일 확인하기
Get-ChildItem d:\test\*
2) 특정한 폴더를 확인한 후 모두 삭제하기
Get-ChildItem d:\test\* | ForEach ($_) {Remove-Item $_.fullname}
3) 폴더의 특정한 파일을 포함한 것만 확인하기(확장자 txt)
Get-ChildItem d:\test\* -Include *.txt
4) 폴더의 특정한 파일을 포함한 것을 확인하되, 특정한 이름(파일 이름이 '업무'로 시작하는 것)이 들어 간 것은 제외하기
Get-ChildItem d:\test\* -Include *.txt -Exclude 업무*.txt
5) 하위 폴더까지 모두 확인하기
Get-ChildItem d:\* -Include *.txt -Recurse
6) 하위 폴더까지 모두 확인한 후 몽땅 삭제하기 (C:\ 아래에 있는 모든 임시 파일(*.tmp))
Get-ChildItem c:\* -Include *.tmp -Recurse | ForEach ($_) {Remove-Item $_.fullname}
7) 원격 컴퓨터의 파일(C:\Test\*)을 확인한 후 몽땅 지우기
원격 컴퓨터로 접속하려면 사전에 원격 컴퓨터에서 접속 허용을 해두어야 한다. Enable-PSRemoting -Force
또는 Group Policy를 사용하여 PS1 스크립트 파일을 적용하도록 해두어야 한다.
Invoke-Command -Computername R2-C -ScriptBlock {Get-ChildItem C:\test\* -Recurse} : 확인만 하기
Invoke-Command -Computername R2-C -ScriptBlock {Get-ChildItem C:\test\* -Recurse| ForEach ($_) {Remove-Item $_.fullname}} : 확인하고 지우기
8) 원격 컴퓨터의 파일 중에서 확장자가 mp3 파일만 확인한 후 모두 삭제하기 (음악 파일 및 동영상 파일 확인)
Invoke-Command -Computername R2-C -ScriptBlock {Get-ChildItem C:\test\* -Include *.mp3 -Recurse} : 확인만 하기
Invoke-Command -Computername R2-C -ScriptBlock {Get-ChildItem C:\test\* -Include *.mp3 -Recurse| ForEach ($_) {Remove-Item $_.fullname}} : 확인하고 지우기
9) 원격 컴퓨터가 많이 있을 때 파일 확인하고 삭제하기
이럴 때는 원격 컴퓨터의 이름을 파일로 만들어 둔다.( c:\computers.txt)
icm -computername (Get-Content c:\computers.txt) -ScriptBlock {Get-ChildItem C:\test\* -Include *.mp3 -Recurse} : 확인만 하기
icm -computername (Get-Content c:\computers.txt) -ScriptBlock {Get-ChildItem C:\test\* -Include *.mp3 -Recurse | ForEach ($_) {Remove-Item $_.fullname}} : 확인하고 지우기
10) 명령 내용이 너무 길기 때문에 위의 명령어를 파워셀 스크립트(.ps1) 파일로 만든 후, 이 파일을 불러 들어 실행하여 삭제하기
스크립트 파일 이름: DeleteMP3.ps1
스크립트 파일 내용: Get-ChildItem C:\test\* -Include *.mp3 -Recurse | ForEach ($_) {Remove-Item $_.fullname}
icm -FilePath c:\DeleteMP3.ps1 -Computername (Get-Content c:\computers.txt)
이렇게 하면 회사에 있는 모든 컴퓨터를 검색하여 mp3 파일을 몽땅 지울 수 있다.
** 주의 사항: ps1 스크립트 파일을 실행하려면 Set-ExecutionPolicy RemoteSigned 로 사전에 설정해두어야 한다.
11) 로컬 컴퓨터의 임시 파일(*.tmp)을 확인하고 지우고자 하면
Get-ChildItem C:\* -Include *.tmp -Recurse : 임시 파일 확인하기
Get-ChildItem C:\* -Include *.tmp -Recurse | | ForEach ($_) {Remove-Item $_.fullname} : 임시 파일 확인한 후 지우기
참고: http://blogs.technet.com/b/heyscriptingguy/archive/2006/10/23/how-can-i-use-windows-powershell-to-delete-all-the-tmp-files-on-a-drive.aspx
2010년 12월 1일 수요일
[Powershell] 버전 정보를 읽어서 출력
파일에서 특정문자열을 검색해서 특정문자 앞에 있는 문자를 출력.
$version1=(Get-Command $source_file).FileversionInfo.FileVersion$version2=$version1.split(" ")[3]
“ “ 특정문자열검색
[] 몇번째값
인수1 : 버전읽을 파일 경로
인수2 : 저정할 파일경로
2개의 인수값을 읽어 version.txt 파일로 저장.
2, 0 , 0, 4 일경우 4를 version.txt파일에 저장함.
$source_file = $args[0]$ver_dir= $args[1]$verinfo="Version.txt"$version1=(Get-Command $source_file).FileversionInfo.FileVersion$version2=$version1.split(" ")[3]set-content -path $ver_dir\$verinfo -value $version2
2010년 10월 7일 목요일
2010년 9월 27일 월요일
asterisk 를 사용하려고 할때
asterisk 검색할때
“\* “이문자를 쓰면됨.
$rc_file = get-Content -path D:\log2.txt$rc_length = $rc_file.Lengthfor ($i =0 ; $i -lt $rc_length; $i++){if ($rc_file[$i] -match "\*\*") {$message+= $rc_file[$i] +"`n"}}set-Content -path D:\SRC\BuildTools\Rlog.txt $message
2010년 9월 15일 수요일
2010년 9월 13일 월요일
파워 쉘 로 자동화하기 (Windows Automation Snapin for Powershell)
WASP(Windows Automation Snapin for Powershell) http://wasp.codeplex.com/
윈도우를 선택, 활성화, 창 크기 변경, 창 닫기, Keyboard,Mouse Action 등을 할 수 있는 PowerShell 자동화 Snapin
Autohot Key 와 비슷한 기능들을 이용 가능할 것 같다.
사용 가능한 명령어들은 아래와 같다.
| •Select-Window - pick windows by process name or window caption (with wildcard support) •Select-ChildWindow - pick all owned windows of another window (eg: dialogs, tool windows) •Select-Control - pick controls (children) of a specific window, by class and/or name and/or index (with wildcard support) -- NOTE: the "Window" can be specified as "-Window 0" to get all parentless windows, which includes windows, dialogs, tooltips, etc... With -Window 0 this returns a true superset of the Select-Window output. •Send-Click - send mouse clicks (any button, with any modifier keys) •Send-Keys - Windows.Forms.SendKeys lets you send keys ... try this: Select-Window notepad | Send-Keys "%(ea)Testing{Enter}{F5}" (and for extra fun, try it with multiple notepad windows open). •Set-WindowActive - yeah, just activates the window •Set-WindowPosition - set any one of (or all of) top, left, width, height on a window ... or maximize/minimize/restore •Get-WindowPosition - get the position (kind-of redundant, actually, since the Window object has it's position as a property) •Remove-Window - closes the specified window |
WASP 1.3 RC 버전이 이글을 쓸때의 신버전이고(20100913) http://wasp.codeplex.com/releases/view/22118
설치는 압축을 해제하면 .아래 3개의 파일이 실행된다.
| Install.ps1 UnInstall.ps1 WASP.dll |
PowerShell 을 실행 후 Install.ps1 을 실행하면 2.0이 설치되어있다고 PSSnapin을 이용해 Import-Module 을 하거나 -Force를 이용해서 하라고 한다.
| PS C:\WASP> .\Install.ps1 You're running PowerShell 2.0, so you don't need to Install this as a PSSnapin, you can use Import-Module (or Add-Module in CTP2) to load it. If you still want to install it as a PSSnapin, re-run this script with -Force |
-Force 명령을 실행하면 아래와 같이 설치가 진행 된다.
| PS C:\WASP> .\Install.ps1 -force 트랜잭트 설치를 실행하고 있습니다. 설치의 Install 단계를 시작하고 있습니다. Install 단계는 완료되었으며 Commit 단계를 시작하고 있습니다. Commit 단계가 완료되었습니다. 트랜잭트 설치가 완료되었습니다. CommandType Name Definition You can also add that line to your Profile script to load it automatically. |
Sample Demo
| ## Open a couple windows(윈도우를 두개 실행) ## list the windows( 윈도우 리스트를 출력) ## Activate Notepad(노트패드를 활성화) ## Close Explorer( 탐색기 종료) ## Run a few more copies of notepad(노트패드를 여러개 실행) ## Move them around so we can see them all ... (Note the use of foreach with the incrementation)위치 변경 ## Put some text into them(텍스트를 입력) Select-Window notepad | Send-Keys "Test Send-Keys !!!" #### Close the first notepad window by pressing ALT+F4, and pressing Alt+N Select-Window notepad | Select -First 1 | Send-Keys "%{F4}" ## Close the next notepad window ... ## Close the next notepad window the hard way Select-Window notepad | Select -First 1 | kill ## A different way to confirm Don't Save (use CLICK instead of keyboard) Select-Window notepad | Select -First 1 | Remove-Window -Passthru | Select-childwindow | select-control| select-control| select-control -title "Do&n't Save" | Send-Click ## But now we have the new -Recurse parameter, so it's easy. Just find the window you want and ... Select-Window notepad | Select -First 1 | Remove-Window -Passthru | Select-childwindow | select-control -title "Do&n't Save" -recurse | Send-Click |
2010년 9월 3일 금요일
PS1 파일 실행할수 있도록 하기
Set-ExecutionPolicy Remotesigned
공유폴더에 위차한 서명되지 않은 파워쉘 실행
Set-ExecutionPolicy Unrestricted
2010년 9월 2일 목요일
Using PowerShell to update AsssemblyFileVersions
Asssemblyfile 버전을 변경해주는 Powershell 스크립트
# SetVersion.ps1## Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.## usage:# from cmd.exe:# powershell.exe SetVersion.ps1 2.8.3.0## from powershell.exe prompt:# .\SetVersion.ps1 2.8.3.0## last saved Time-stamp: <Wednesday, April 23, 2008 11:46:40 (by dinoch)>#function Usage{echo "Usage: ";echo " from cmd.exe: ";echo " powershell.exe SetVersion.ps1 2.8.3.0";echo " ";echo " from powershell.exe prompt: ";echo " .\SetVersion.ps1 2.8.3.0";echo " ";}function Update-SourceVersion{Param ([string]$Version)$NewVersion = 'AssemblyVersion("' + $Version + '")';$NewFileVersion = 'AssemblyFileVersion("' + $Version + '")';foreach ($o in $input){Write-output $o.FullName$TmpFile = $o.FullName + ".tmp"get-content $o.FullName |%{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } > $TmpFilemove-item $TmpFile $o.FullName -force}}function Update-AllAssemblyInfoFiles ( $version ){foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" ){get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;}}# validate arguments$r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");if ($r.Success){Update-AllAssemblyInfoFiles $args[0];}else{echo " ";echo "Bad Input!"echo " ";Usage ;}
Building SharePoint Projects with PowerShell and MSBuild - SharePoint Depth Wiki - SharePoint Depth