2010. 9. 15. 19:18


안녕하세요 @우주인입니다.
이번에는 Add-PsSnapIn를 이용하여 스냅인을 추가하는 법을 살펴보고자 합니다.
Add-PsSnapIn를 이용하면 내장되어 있는 명령어외에 해당 스냅인에서 지원하는 cmdlet를 모두 이용할 수 있습니다.

Sql이나 Exchange서버, AD등을 컨트롤하는데 많이 쓰이며
저같은 경우 쉐어포인트를 주로 컨트롤하는 이용합니다.

이용법은 help Add-PsSnapIn 를 통해 보시면 자세히 나와있으며 주로 Add-PsSnapIn NAME 으로 해당 스냅인을 추가합니다.

추가할 수 있는 스냅인의 종류를 볼려면 아래와 같이 Get-PSSnapin를 이용하시면 됩니다.


역시 제 PC에는 쉐어포인트 관련 스냅인이 지원되는군요

그럼 간단히 쉐어포인트에 사이트모음을 가져와 볼까요


당연히 위에 Add-PSSnapin 을 이용해 쉐어포인트 파워쉘 스냅인을 가져오지 않았다면 Get-SPSite는 실행시 오류가 발생합니다.

이와 같이 원하는 스냅인을 추가하여 서비스를 컨트롤 할 수 있습니다.


자신의 PC에 있는 모든 스냅인을 등록하고자 할때는 아래와 같이 한번에 처리가 가능합니다.




참고로 AD의 경우는
C:\PS>add-PSSnapIn Microsoft.Exchange, Microsoft.Windows.AD
설명
-----------
이 명령은 Microsoft Exchange 및 Active Directory 스냅인을 현재 세션에 추가합니다.



원본: http://vstarmanv.tistory.com/entry/Add-PSSnapin

'Powershell > @우주인' 카테고리의 다른 글

[MSSQL]WMI for SQL Management(2)-ClientNetworkProtocol  (0) 2010.10.05
Clip을 이용한 복사  (0) 2010.09.15
PowerShell Default Snap-Ins  (0) 2010.09.15
.NET Assembly load  (0) 2010.09.15
[MSSQL]WMI for SQL Management(1)  (0) 2010.09.15
Posted by 알 수 없는 사용자
:
2010. 9. 15. 19:18

파워쉘 Defalut 스냅인

기본적으로 파워쉘이 설치된 환경이라면 7개의 core snap-in이 로드되며, 이 때문에 해당 cmdlets를 사용할 수 있습니다.  당연히 core snap-in 들은 각자의 namespace를 가지고 있습니다.

 

1. Core (MicroSoft.PowerShell.core)
 
-       파워쉘 엔진, alias, 환경, 변수 , 함수에 관련되 cmdlet 

Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "core"}

 

2. Host (MicroSoft.PowerShell.Host)

 - hosting에 관련된 스냅인

Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "host"}

 

3. PowerShell.Management (MicroSoft.PowerShell.Management)

 - 프로세스나 서비스 관리 등 기타 윈도우 management 관련 cmdlet

Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "PowerShell.Management"}

 

4. Security (MicroSoft.PowerShell.Security)

 - 파워쉘 보안관련 스냅인

Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "Security"}


5. Utility (MicroSoft.PowerShell.Host)

 - Write-hostFormat-list 와 같은data manipulate 관련 cmdlets snap-in

Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "Utility"} 


6.
Diagnostics (MicroSoft.PowerShell.Diagnostics)

 - performance counters 나 이벤트 로그 관련 cmdlets snap-in

 Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "Diagnostics"}


7.
WsMan.Management (MicroSoft.WsMan.Management)

 - WsMan 관련 cmdlets snap-in

Get-Command -commandtype cmdlet | Where-Object {$_.PSSnapin -match "WsMan.Management"}

 

 

 원본: http://vstarmanv.tistory.com/entry/PowerShell-Default-Snap-Ins



'Powershell > @우주인' 카테고리의 다른 글

Clip을 이용한 복사  (0) 2010.09.15
Add-PSSnapin  (0) 2010.09.15
.NET Assembly load  (0) 2010.09.15
[MSSQL]WMI for SQL Management(1)  (0) 2010.09.15
파워쉘을 이용한 DOM 사용  (0) 2010.09.09
Posted by 알 수 없는 사용자
:
2010. 7. 22. 09:00


안녕하세요? 윈디안입니다!

파워쉘 스냅인 중 흥미로운 녀석이 있어 소개해 드리려 합니다.

WASP(Windows Automation Snapin for Powershell)
http://wasp.codeplex.com/

이 녀석은 무엇일까요?

이름에도 나와 있듯이 자동화(Automation)를 구현할 수 있는 스냅인입니다.

그럼 어떻게 자동화를 구현할까요?

AutoHotkey라는 프로그램 들어 보신적 있나요? 매크로를 이용한 자동화 프로그램입니다.
저는 이 것과 유사하다고 느꼈습니다.

지원하는 Cmdlet은 아래와 같습니다.


  • 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
  • Cmdlet을 보시면 느낌이 확 오시죠? 윈도우를 선택, 활성화,창크기 변경, 창 닫기, Keyboard,Mouse Action 등을 할 수 있습니다.

    http://wasp.codeplex.com/releases/22118/download/55849

    압축파일을 다운로드 하면 파일이 3개 있는데 이 중 Install.ps1을 파워쉘에서 실행하시면 됩니다.
    저는 -Force 스위치를 사용하여 설치했습니다.

    PS C:\Users\windian7.SDS\Downloads\WASP\WASP> dir


        디렉터리: C:\Users\windian7.SDS\Downloads\WASP\WASP


    Mode                LastWriteTime     Length Name
    ----                -------------     ------ ----
    -a---      2009-01-20  오전 12:50       2570 Install.ps1
    -a---      2009-01-20  오전 12:53        520 UnInstall.ps1
    -a---      2009-01-21  오전 11:13      43008 WASP.dll


    PS C:\Users\windian7.SDS\Downloads\WASP\WASP> .\Install.ps1 -force
    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
    Microsoft (R) .NET Framework Installation utility Version 2.0.50727.4927
    Copyright (c) Microsoft Corporation. All rights reserved.


    트랜잭트 설치를 실행하고 있습니다.

    설치의 Install 단계를 시작하고 있습니다.
    C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.dll 어셈블리의 진행 상황을 보려면
     로그 파일 내용을 검토하십시오.
    파일은 C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.InstallLog 위치에 있습니다
    .
    어셈블리 'C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.dll'을(를) 설치하고 있
    습니다.
    영향을 받는 매개 변수:
       assemblypath = C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.dll
       logfile = C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.InstallLog
       logtoconsole =

    Install 단계는 완료되었으며 Commit 단계를 시작하고 있습니다.
    C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.dll 어셈블리의 진행 상황을 보려면
     로그 파일 내용을 검토하십시오.
    파일은 C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.InstallLog 위치에 있습니다
    .
    어셈블리 'C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.dll'을(를) 커밋하고 있
    습니다.
    영향을 받는 매개 변수:
       assemblypath = C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.dll
       logfile = C:\Users\windian7.SDS\Downloads\WASP\WASP\WASP.InstallLog
       logtoconsole =

    Commit 단계가 완료되었습니다.

    트랜잭트 설치가 완료되었습니다.

    CommandType     Name                            Definition
    -----------     ----                            ----------
    Cmdlet          Get-WindowPosition              Get-WindowPosition [-Window]...
    Cmdlet          Remove-Window                   Remove-Window [-Window] <Win...
    Cmdlet          Select-ChildWindow              Select-ChildWindow [-Window]...
    Cmdlet          Select-Control                  Select-Control [[-Index] <In...
    Cmdlet          Select-Window                   Select-Window [[-ProcessName...
    Cmdlet          Send-Click                      Send-Click [[-Left] <Int32>]...
    Cmdlet          Send-Keys                       Send-Keys [-Keys] <String> [...
    Cmdlet          Set-WindowActive                Set-WindowActive [-Window] <...
    Cmdlet          Set-WindowPosition              Set-WindowPosition [[-Left] ...
    To load the Windows Automation Snapin in the future, you need to run:
    Add-PSSnapin WASP

    You can also add that line to your Profile script to load it automatically.



    설치 완료 후 다음 파워쉘 실행 시 "Add-PSSnapin WASP"을 통해서 스냅인을 로드해야 Cmdlet을 사용할 수 있습니다.
    (프로필을 통해서 자동으로 로드 되도록 할 수도 있습니다.)


    그럼 예제를 보겠습니다.

    ## 윈도우를 두개 실행합니다.
    notepad.exe
    explorer.exe


    ## 윈도우 리스트를 출력합니다.
    Select-Window | ft –auto

    ## 노트패드를 활성화합니다.
    Select-Window notepad* | Set-WindowActive

    ## 탐색기를 종료합니다.
    Select-Window explorer | Select -First 1 | Remove-WIndow

    ## 노트패드를 여러개 실행합니다.
    notepad; notepad; notepad; notepad;

    ## 노트패드 위치 변경하기
    $i = 1;$t = 100; Select-Window notepad | ForEach { Set-WindowPosition -X 20 -Y (($i++)*$t) -Window $_ }

    ## 노트패드에 텍스트를 입력합니다.
    Select-Window notepad | Send-Keys "테스트입니다!!!"

    ## 첫번째 notepad를 ALT+F4로 종료합니다.
    Select-Window notepad | Select -First 1 | Send-Keys "%{F4}"

    ## "Remove-Window" Cmdlet을 통해 notepad를 종료합니다. 키 명령을 통해서 저장하지 않고 종료합니다.
    Select-Window notepad | Select -First 1 | Remove-Window -Passthru | Select-ChildWindow | Send-Keys "n"

    ##  ProcessID 파이프를 통해 Kill 명령으로 notepad를 종료합니다.
    Select-Window notepad | Select -First 1 | kill

     

    이렇게 파워쉘을 통해서 윈도우를 컨트롤 할 수 있습니다.
    응용하기에 따라 유용한 도구가 될 것 같습니다.

    그럼 다음 포스팅에서 뵙겠습니다.

    PS. 스냅인 사용을 위해서는 Add-PSSanpin 명령을 통해 해당 스냅인을 로드해야 합니다. 기억하세요.

    Posted by 알 수 없는 사용자
    :

    BLOG main image
    Windows Server를 공부 하는 사람들의 팀블로그 by 마성민

    카테고리

    분류 전체보기 (76)
    Windows (2)
    Powershell (56)
    AD (0)
    Exchange (6)
    System Center (9)
    IIS (0)
    SQL (3)
    Sharepoint (0)

    태그목록

    Tistory Cumulus Flash tag cloud by BLUEnLIVE requires Flash Player 9 or better.

    Total :
    Today : Yesterday :