今回は自分で使うようにPowerShellのよく使うコマンドレットやTipsをまとめてみます。随時更新する予定!

Get-Command

Get-Commandでコマンドレットの一覧を取得できます。

PS C:\> Get-Command

 

 

CommandType     Name                                      Definition

 

-----------     ----                                      ----------

 

Alias           %                                         ForEach-Object

 

Alias           ?                                         Where-Object

 

Function        A:                                        Set-Location A:

 

Alias           ac                                        Add-Content

 

Cmdlet          Add-Computer                              Add-Computer [-DomainName]  [-...

 

Cmdlet          Add-Content                               Add-Content [-Path]  [-Value...

 

Cmdlet          Add-History                               Add-History [[-InputObject] 

findstrでフィルタリングすることで探すのもいいと思います。

PS C:> Get-Command | findstr Alias


 

Alias % ForEach-Object


 

Alias ? Where-Object


 

Alias ac Add-Content


 

Alias asnp Add-PSSnapIn


 

Alias cat Get-Content


 

Alias cd Set-Location


 

Alias chdir Set-Location


 

Alias clc Clear-Content


 

Alias clear Clear-Host


 

Alias clhy Clear-History


 

Alias cli Clear-Item


 

Alias clp Clear-ItemProperty


 

Alias cls Clear-Host


 

Alias clv Clear-Variable


 

Alias compare Compare-Object


 

Alias copy Copy-Item


 

Alias cp Copy-Item


 

Alias cpi Copy-Item


 

Alias cpp Copy-ItemProperty


 

Alias cvpa Convert-Path


 

Alias dbp Disable-PSBreakpoint


 

Alias del Remove-Item


 

Alias diff Compare-Object


 

Alias dir Get-ChildItem


 

Alias ebp Enable-PSBreakpoint


 

Alias echo Write-Output


 

Alias epal Export-Alias


 

Alias epcsv Export-Csv


 

Alias epsn Export-PSSession


 

Alias erase Remove-Item


 

Alias etsn Enter-PSSession


 

Cmdlet Export-Alias Export-Alias [-Path] [[-Name]…


 

Alias exsn Exit-PSSession


 

Alias fc Format-Custom


 

Alias fl Format-List


 

Alias foreach ForEach-Object


 

Alias ft Format-Table


 

Alias fw Format-Wide


 

Alias gal Get-Alias


 

Alias gbp Get-PSBreakpoint


 

Alias gc Get-Content


 

Alias gci Get-ChildItem


 

Alias gcm Get-Command


 

Alias gcs Get-PSCallStack


 

Alias gdr Get-PSDrive


 

Cmdlet Get-Alias Get-Alias [[-Name] ] [-Exclu…


 

Alias ghy Get-History


 

Alias gi Get-Item


 

Alias gjb Get-Job


 

Alias gl Get-Location


 

Alias gm Get-Member


 

Alias gmo Get-Module


 

Alias gp Get-ItemProperty


 

Alias gps Get-Process


 

Alias group Group-Object


 

Alias gsn Get-PSSession


 

Alias gsnp Get-PSSnapIn


 

Alias gsv Get-Service


 

Alias gu Get-Unique


 

Alias gv Get-Variable


 

Alias gwmi Get-WmiObject


 

Alias h Get-History


 

Alias history Get-History


 

Alias icm Invoke-Command


 

Alias iex Invoke-Expression


 

Alias ihy Invoke-History


 

Alias ii Invoke-Item


 

Cmdlet Import-Alias Import-Alias [-Path] [-Scope …


 

Alias ipal Import-Alias


 

Alias ipcsv Import-Csv


 

Alias ipmo Import-Module


 

Alias ipsn Import-PSSession


 

Alias ise powershell_ise.exe


 

Alias iwmi Invoke-WMIMethod


 

Alias kill Stop-Process


 

Alias lp Out-Printer


 

Alias ls Get-ChildItem


 

Alias man help


 

Alias md mkdir


 

Alias measure Measure-Object


 

Alias mi Move-Item


 

Alias mount New-PSDrive


 

Alias move Move-Item


 

Alias mp Move-ItemProperty


 

Alias mv Move-Item


 

Alias nal New-Alias


 

Alias ndr New-PSDrive


 

Cmdlet New-Alias New-Alias [-Name] [-Value]

Get-Help

Get-Help でコマンドレットのヘルプを表示できます。

PS C:\> Get-Help Get-Item

 

 

名前

 

Get-Item

 

 

概要

 

指定された場所にある項目を取得します。

 

 

 

構文

 

Get-Item [-LiteralPath] string[]> [-Credential ] [-Exclude string[]>] [-Filter

 

string>] [-Force] [-Include string[]>] [-UseTransaction] []

 

 

Get-Item [-Path] string[]> [-Credential ] [-Exclude string[]>] [-Filter string

 

>] [-Force] [-Include string[]>] [-UseTransaction] []

 

 

 

説明

 

Get-Item コマンドレットは、指定された場所の項目を取得します。ワイルドカード文字 (*) を使用して

 

項目のすべての内容を要求しない限り、指定した場所にある項目の内容は取得されません。

 

 

Windows PowerShell の各プロバイダーで Get-Item コマンドレットを使用することで、異なる種類のデー

 

タ ストアの間を移動できるようになります。

 

 

 

関連するリンク

 

Online version: http://go.microsoft.com/fwlink/?LinkID=113319

 

about_Providers

 

Clear-Item

 

Copy-Item

 

Invoke-Item

 

Move-Item

 

Set-Item

 

New-Item

 

Remove-Item

 

Rename-Item

 

 

注釈

 

例を参照するには、次のように入力してください: "get-help Get-Item -examples".

 

詳細を参照するには、次のように入力してください: "get-help Get-Item -detailed".

 

技術情報を参照するには、次のように入力してください: "get-help Get-Item -full".

 

Get-Help –full で詳細なヘルプを表示できます。コマンド実行サンプルもあるので非常に参考になります。

PS C:\> Get-Help -full Get-Item

 

 

名前

 

Get-Item

 

 

概要

 

指定された場所にある項目を取得します。

 

 

構文

 

Get-Item [-LiteralPath] string[]> [-Credential ] [-Exclude string[]>] [-Filter

 

string>] [-Force] [-Include string[]>] [-UseTransaction] []

 

 

Get-Item [-Path] string[]> [-Credential ] [-Exclude string[]>] [-Filter string

 

>] [-Force] [-Include string[]>] [-UseTransaction] []

 

 

 

説明

 

Get-Item コマンドレットは、指定された場所の項目を取得します。ワイルドカード文字 (*) を使用して

 

項目のすべての内容を要求しない限り、指定した場所にある項目の内容は取得されません。

 

 

Windows PowerShell の各プロバイダーで Get-Item コマンドレットを使用することで、異なる種類のデー

 

タ ストアの間を移動できるようになります。

 

 

 

パラメーター

 

-Credential 

 

この処理を実行するアクセス許可を持つユーザー アカウントを指定します。既定値は現在のユーザー

 

です。

 

 

"User01" や "Domain01\User01" のようなユーザー名を入力するか、Get-Credential コマンドレット

 

で生成されるような PSCredential オブジェクトを入力します。ユーザー名を入力すると、パスワー

 

ドの入力を促すメッセージが表示されます。

 

 

このパラメーターは、Windows PowerShell でインストールされるプロバイダーではサポートされてい

 

ません。

 

 

必須                         false

 

位置                         named

 

既定値

 

パイプライン入力を許可する   true (ByPropertyName)

 

ワイルドカード文字を許可する false

 

 

-Exclude string[]>

 

指定した項目を除外します。このパラメーターの値は、Path パラメーターを修飾します。"*.txt" な

 

どのパス要素またはパターンを入力します。ワイルドカードを使用できます。

 

 

Exclude パラメーターは、C:\Windows\* のように、コマンドに項目の内容が含まれている場合のみ有

 

効です。この場合、ワイルドカード文字は C:\Windows ディレクトリの内容を示します。

 

 

必須                         false

 

位置                         named

 

既定値

 

パイプライン入力を許可する   false

 

ワイルドカード文字を許可する false

 

 

-Filter string>

 

プロバイダーの形式や言語でフィルターを指定します。このパラメーターの値は、Path パラメーター

 

を修飾します。ワイルドカードを使用できるかどうかなど、フィルターの構文はプロバイダーによっ

 

て異なります。フィルターは他のパラメーターよりも効率が良い方法です。これは、オブジェクトを

 

取得した後に Windows PowerShell がオブジェクトをフィルターするのではなく、オブジェクトを取

 

得する際にプロバイダーがフィルターを適用するためです。

 

 

必須                         false

 

位置                         named

 

既定値

 

パイプライン入力を許可する   false

 

ワイルドカード文字を許可する false

 

 

-Force []

 

非表示の項目など、設定しないとアクセスできない項目をコマンドレットで取得できるようにします

 

。実装はプロバイダーごとに異なります。詳細については、「about_Providers」を参照してください

 

。Force パラメーターを使用しても、コマンドレットはセキュリティ制限を上書きできません。

 

 

必須                         false

 

位置                         named

 

既定値

 

パイプライン入力を許可する   false

 

ワイルドカード文字を許可する false

 

 

-Include string[]>

 

指定した項目だけを取得します。このパラメーターの値は、Path パラメーターを修飾します。"*.txt

 

" などのパス要素またはパターンを入力します。ワイルドカードを使用できます。

 

 

Include パラメーターは、C:\Windows\* のように、コマンドに項目の内容が含まれている場合のみ有

 

効です。この場合、ワイルドカード文字は C:\Windows ディレクトリの内容を示します。

 

 

必須                         false

 

位置                         named

 

既定値

 

パイプライン入力を許可する   false

 

ワイルドカード文字を許可する false

 

 

-LiteralPath string[]>

 

項目のパスを指定します。Path と異なり、LiteralPath の値は入力したとおりに使用されます。ワイ

 

ルドカードとして解釈される文字はありません。パスにエスケープ文字が含まれている場合は、単一

 

引用符で囲みます。単一引用符で囲んだ文字はエスケープ シーケンスとして解釈されません。

 

 

必須                         true

 

位置                         1

 

既定値

 

パイプライン入力を許可する   true (ByPropertyName)

 

ワイルドカード文字を許可する false

 

 

-Path string[]>

 

項目のパスを指定します。Get-Item は指定された場所にある項目を取得します。ワイルドカードを使

 

用できます。このパラメーターは必須ですが、パラメーター名 (Path) は省略可能です。

 

 

ドット (.) を使用して現在の場所を指定します。現在の場所にあるすべての項目を指定するには、ワ

 

イルドカード文字 (*) を使用します。

 

 

必須                         true

 

位置                         1

 

既定値

 

パイプライン入力を許可する   true (ByValue, ByPropertyName)

 

ワイルドカード文字を許可する false

 

 

-UseTransaction []

 

コマンドを有効なトランザクションに含めます。このパラメーターは、トランザクションの進行中の

 

み有効です。詳細については、「about_Transactions」を参照してください。

 

 

必須                         false

 

位置                         named

 

既定値

 

パイプライン入力を許可する   false

 

ワイルドカード文字を許可する false

 

 

 

このコマンドレットは、次の共通パラメーターをサポートします: Verbose、

 

Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、

 

OutBuffer、および OutVariable。詳細については、

 

「get-help about_commonparameters」と入力してヘルプを参照してください。

 

 

入力

 

System.String

 

パイプを使用してパスを含む文字列を Get-Item に渡すことができます。

 

 

 

出力

 

Object

 

Get-Item は、取得するオブジェクトを返します。この型は、パス内のオブジェクトの型によって決ま

 

ります。

 

 

 

メモ

 

 

 

Get-Item は、その組み込みエイリアスである "gi" で参照することもできます。詳細については、「

 

about_Aliases」を参照してください。

 

 

Get-Item は項目のみを取得し、その内容は取得しません。したがって、Recurse パラメーターがあり

 

ません。項目の内容を再帰的に取得するには、Get-ChildItem を使用します。

 

 

レジストリ内を移動するには、Get-Item を使用してレジストリ キーを取得し、Get-ItemProperty を

 

使用してレジストリ値とデータを取得します。レジストリ値はレジストリ キーのプロパティと見なさ

 

れます。

 

 

Get-Item コマンドレットは、プロバイダーによって公開されているデータを使用するように設計され

 

ています。セッションで使用可能なプロバイダーの一覧を表示するには、「Get-PsProvider」と入力

 

します。詳細については、「about_Providers」を参照してください。

 

 

 

-------------------------- 例 1 --------------------------

 

 

C:\PS>get-item .

 

 

Directory: C:\

 

 

Mode                LastWriteTime     Length Name

 

----                -------------     ------ ----

 

d----         7/26/2006  10:01 AM            ps-test

 

 

 

説明

 

-----------

 

このコマンドは、現在のディレクトリを取得します。ドット (.) は、現在の場所にある項目を表します (

 

内容ではありません)。

 

 

 

 

 

 

-------------------------- 例 2 --------------------------

 

 

C:\PS>get-item *

 

 

Directory: C:\ps-test

 

 

Mode                LastWriteTime     Length Name

 

----                -------------     ------ ----

 

d----         7/26/2006   9:29 AM            Logs

 

d----         7/26/2006   9:26 AM            Recs

 

-a---         7/26/2006   9:28 AM         80 date.csv

 

-a---         7/26/2006  10:01 AM         30 filenoext

 

-a---         7/26/2006   9:30 AM      11472 process.doc

 

-a---         7/14/2006  10:47 AM         30 test.txt

 

 

 

説明

 

-----------

 

このコマンドは、現在のディレクトリ内のすべての項目を取得します。ワイルドカード文字 (*) は、現在

 

の項目のすべての内容を表します。

 

 

 

 

 

 

-------------------------- 例 3 --------------------------

 

 

C:\PS>get-item C:\

 

 

 

説明

 

-----------

 

このコマンドは、C: ドライブの現在のディレクトリを取得します。ここで取得するオブジェクトは、ディ

 

レクトリのみを表します。その内容は表しません。

 

 

 

 

 

 

-------------------------- 例 4 --------------------------

 

 

C:\PS>get-item C:\*

 

 

 

説明

 

-----------

 

このコマンドは、C: ドライブ中の項目を取得します。ワイルドカード文字 (*) は、コンテナーだけでな

 

く、コンテナー内のすべての項目を表します。

 

 

Windows PowerShell では、従来の *.* ではなく、単一のアスタリスク (*) を使用して内容を取得します

 

。形式は文字どおりに解釈されるため、*.* を使用すると、名前にドットが含まれていないディレクトリ

 

やファイルは取得されません。

 

 

 

 

 

 

-------------------------- 例 5 --------------------------

 

 

C:\PS>(get-item C:\Windows).LastAccessTime

 

 

 

説明

 

-----------

 

このコマンドは、C:\Windows ディレクトリの LastAccessTime プロパティを取得します。LastAccessTime

 

は、ファイル システム ディレクトリの 1 つのプロパティにすぎません。ディレクトリのすべてのプロ

 

パティを参照するには、「(Get-Item ) | Get-Member」と入力します。

 

 

 

 

 

 

-------------------------- 例 6 --------------------------

 

 

C:\PS>get-item hklm:\software\microsoft\powershell\1\shellids\microsoft.powershell\*

 

 

 

説明

 

-----------

 

このコマンドを実行すると、Microsoft.PowerShell レジストリ キーの内容が表示されます。Windows Pow

 

erShell Registry プロバイダーでは、Get-Item を使用してレジストリ キーとサブキーを取得できますが

 

、レジストリ値とデータを取得するには、Get-ItemProperty を使用する必要があります。

 

 

 

 

 

 

-------------------------- 例 7 --------------------------

 

 

C:\PS>get-item c:\Windows\* -include *.* -exclude w*

 

 

 

説明

 

-----------

 

このコマンドを実行すると、Windows ディレクトリ内の項目のうち、名前にドット (.) が含まれ、先頭が

 

w* でないものが取得されます。このコマンドは、パスにワイルドカード文字 (*) が含まれ、項目の内容

 

が指定されている場合にだけ有効です。

 

 

 

 

 

 

 

関連するリンク

 

Online version: http://go.microsoft.com/fwlink/?LinkID=113319

 

about_Providers

 

Clear-Item

 

Copy-Item

 

Invoke-Item

 

Move-Item

 

Set-Item

 

New-Item

 

Remove-Item

 

Rename-Item

 

Get-Member

Get-Memberでオブジェクトの型、プロパティ、メソッドの確認が行えます。このあたりは完全に.net frameworkの世界です。パイプでオブジェクトを渡すことが多いでしょう。

PS C:\> Get-Item c:\ | Get-Member

 

 

 

TypeName: System.IO.DirectoryInfo

 

 

Name                      MemberType     Definition

 

----                      ----------     ----------

 

Mode                      CodeProperty   System.String Mode{get=Mode;}

 

Create                    Method         System.Void Create(System.Security.AccessControl.Direct...

 

CreateObjRef              Method         System.Runtime.Remoting.ObjRef CreateObjRef(type reques...

 

CreateSubdirectory        Method         System.IO.DirectoryInfo CreateSubdirectory(string path)...

 

Delete                    Method         System.Void Delete(), System.Void Delete(bool recursive)

 

Equals                    Method         bool Equals(System.Object obj)

 

GetAccessControl          Method         System.Security.AccessControl.DirectorySecurity GetAcce...

 

GetDirectories            Method         System.IO.DirectoryInfo[] GetDirectories(string searchP...

 

GetFiles                  Method         System.IO.FileInfo[] GetFiles(string searchPattern), Sy...

 

GetFileSystemInfos        Method         System.IO.FileSystemInfo[] GetFileSystemInfos(string se...

 

GetHashCode               Method         int GetHashCode()

 

GetLifetimeService        Method         System.Object GetLifetimeService()

 

GetObjectData             Method         System.Void GetObjectData(System.Runtime.Serialization....

 

GetType                   Method         type GetType()

 

InitializeLifetimeService Method         System.Object InitializeLifetimeService()

 

MoveTo                    Method         System.Void MoveTo(string destDirName)

 

Refresh                   Method         System.Void Refresh()

 

SetAccessControl          Method         System.Void SetAccessControl(System.Security.AccessCont...

 

ToString                  Method         string ToString()

 

PSChildName               NoteProperty   System.String PSChildName=C:\

 

PSDrive                   NoteProperty   System.Management.Automation.PSDriveInfo PSDrive=C

 

PSIsContainer             NoteProperty   System.Boolean PSIsContainer=True

 

PSParentPath              NoteProperty   System.String PSParentPath=

 

PSPath                    NoteProperty   System.String PSPath=Microsoft.PowerShell.Core\FileSyst...

 

PSProvider                NoteProperty   System.Management.Automation.ProviderInfo PSProvider=Mi...

 

Attributes                Property       System.IO.FileAttributes Attributes {get;set;}

 

CreationTime              Property       System.DateTime CreationTime {get;set;}

 

CreationTimeUtc           Property       System.DateTime CreationTimeUtc {get;set;}

 

Exists                    Property       System.Boolean Exists {get;}

 

Extension                 Property       System.String Extension {get;}

 

FullName                  Property       System.String FullName {get;}

 

LastAccessTime            Property       System.DateTime LastAccessTime {get;set;}

 

LastAccessTimeUtc         Property       System.DateTime LastAccessTimeUtc {get;set;}

 

LastWriteTime             Property       System.DateTime LastWriteTime {get;set;}

 

LastWriteTimeUtc          Property       System.DateTime LastWriteTimeUtc {get;set;}

 

Name                      Property       System.String Name {get;}

 

Parent                    Property       System.IO.DirectoryInfo Parent {get;}

 

Root                      Property       System.IO.DirectoryInfo Root {get;}

 

BaseName                  ScriptProperty System.Object BaseName {get=$this.Name;}

 

Format-List

出力結果のオブジェクトのプロパティをリスト形式で出力します。引数を与えると出力するプロパティを選択することもできます。出力フォーマットを指定しないと省略されてしまってすべて表示されないケースが多いので重宝します。

PS C:\> Get-Item * | Format-List

 

 

 

ディレクトリ: C:\

 

 

 

 

Name           : PerfLogs

 

CreationTime   : 2009/07/14 11:37:05

 

LastWriteTime  : 2009/07/14 11:37:05

 

LastAccessTime : 2009/07/14 11:37:05

 

 

Name           : Program Files

 

CreationTime   : 2009/07/14 11:37:05

 

LastWriteTime  : 2012/02/23 22:33:31

 

LastAccessTime : 2012/02/23 22:33:31

 

 

Name           : Users

 

CreationTime   : 2009/07/14 11:37:05

 

LastWriteTime  : 2012/01/11 23:31:26

 

LastAccessTime : 2012/01/11 23:31:26

 

 

Name           : Windows

 

CreationTime   : 2009/07/14 11:37:05

 

LastWriteTime  : 2012/02/20 23:36:09

 

LastAccessTime : 2012/02/20 23:36:09

 

 

Name           : autoexec.bat

 

Length         : 24

 

CreationTime   : 2009/07/14 11:04:04

 

LastWriteTime  : 2009/06/11 6:42:20

 

LastAccessTime : 2009/07/14 11:04:04

 

VersionInfo    : File:             C:\autoexec.bat

 

InternalName:

 

OriginalFilename:

 

FileVersion:

 

FileDescription:

 

Product:

 

ProductVersion:

 

Debug:            False

 

Patched:          False

 

PreRelease:       False

 

PrivateBuild:     False

 

SpecialBuild:     False

 

Language:

 

 

 

Name           : config.sys

 

Length         : 10

 

CreationTime   : 2009/07/14 11:04:04

 

LastWriteTime  : 2009/06/11 6:42:20

 

LastAccessTime : 2009/07/14 11:04:04

 

VersionInfo    : File:             C:\config.sys

 

InternalName:

 

OriginalFilename:

 

FileVersion:

 

FileDescription:

 

Product:

 

ProductVersion:

 

Debug:            False

 

Patched:          False

 

PreRelease:       False

 

PrivateBuild:     False

 

SpecialBuild:     False

 

Language:

 

 

 

 

 

Out-GridView

Out-GridViewで結果をGUIのテーブルで表示できます。しかもそこからフィルタもかけることができるので便利に使えるケースも多いと思います。

PS C:\> Get-Item c:\ | Get-Member | Out-GridView

 

image

Where-Object

オブジェクトの中から目的のオブジェクトのみを抜き出す。パイプの途中で非常によく使います。

PS C:\> Get-Process | Where-Object { $_.WS -ge 50MB }

 

 

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName

 

-------  ------    -----      ----- -----   ------     -- -----------

 

1678      30    50100      77476   438    25.16   3472 chrome

 

125      10    64060      64848   187     4.01   3900 chrome

 

472      19    45448      51652   145     8.72   3508 Dropbox

 

605      30    22308      54392   323     8.96   4108 POWERPNT

 

501      13    52784      58948   117            1144 svchost

 

835      60   106332     111388   428    65.59   3980 WindowsLiveWriter

 

Group-Object

同じプロパティを持つオブジェクトをまとめることができます。

PS C:\> Get-Alias | Group-Object Definition

 

 

Count Name                      Group

 

----- ----                      -----

 

2 ForEach-Object            {%, foreach}

 

2 Where-Object              {?, where}

 

1 Add-Content               {ac}

 

1 Add-PSSnapIn              {asnp}

 

3 Get-Content               {cat, gc, type}

 

3 Set-Location              {cd, chdir, sl}

 

1 Clear-Content             {clc}

 

2 Clear-Host                {clear, cls}

 

1 Clear-History             {clhy}

 

1 Clear-Item                {cli}

 

1 Clear-ItemProperty        {clp}

 

1 Clear-Variable            {clv}

 

2 Compare-Object            {compare, diff}

 

3 Copy-Item                 {copy, cp, cpi}

 

1 Copy-ItemProperty         {cpp}

 

1 Convert-Path              {cvpa}

 

1 Disable-PSBreakpoint      {dbp}

 

6 Remove-Item               {del, erase, rd, ri...}

 

3 Get-ChildItem             {dir, gci, ls}

 

1 Enable-PSBreakpoint       {ebp}

 

2 Write-Output              {echo, write}

 

1 Export-Alias              {epal}

 

1 Export-Csv                {epcsv}

 

1 Export-PSSession          {epsn}

 

1 Enter-PSSession           {etsn}

 

1 Exit-PSSession            {exsn}

 

1 Format-Custom             {fc}

 

1 Format-List               {fl}

 

1 Format-Table              {ft}

 

1 Format-Wide               {fw}

 

1 Get-Alias                 {gal}

 

1 Get-PSBreakpoint          {gbp}

 

1 Get-Command               {gcm}

 

1 Get-PSCallStack           {gcs}

 

1 Get-PSDrive               {gdr}

 

3 Get-History               {ghy, h, history}

 

1 Get-Item                  {gi}

 

1 Get-Job                   {gjb}

 

2 Get-Location              {gl, pwd}

 

1 Get-Member                {gm}

 

1 Get-Module                {gmo}

 

1 Get-ItemProperty          {gp}

 

2 Get-Process               {gps, ps}

 

1 Group-Object              {group}

 

1 Get-PSSession             {gsn}

 

1 Get-PSSnapIn              {gsnp}

 

1 Get-Service               {gsv}

 

1 Get-Unique                {gu}

 

1 Get-Variable              {gv}

 

1 Get-WmiObject             {gwmi}

 

1 Invoke-Command            {icm}

 

1 Invoke-Expression         {iex}

 

2 Invoke-History            {ihy, r}

 

1 Invoke-Item               {ii}

 

1 Import-Alias              {ipal}

 

1 Import-Csv                {ipcsv}

 

1 Import-Module             {ipmo}

 

1 Import-PSSession          {ipsn}

 

1 powershell_ise.exe        {ise}

 

1 Invoke-WMIMethod          {iwmi}

 

2 Stop-Process              {kill, spps}

 

1 Out-Printer               {lp}

 

1 help                      {man}

 

1 mkdir                     {md}

 

1 Measure-Object            {measure}

 

3 Move-Item                 {mi, move, mv}

 

2 New-PSDrive               {mount, ndr}

 

1 Move-ItemProperty         {mp}

 

1 New-Alias                 {nal}

 

1 New-Item                  {ni}

 

1 New-Module                {nmo}

 

1 New-PSSession             {nsn}

 

1 New-Variable              {nv}

 

1 Out-GridView              {ogv}

 

1 Out-Host                  {oh}

 

1 Pop-Location              {popd}

 

1 Push-Location             {pushd}

 

1 Remove-PSBreakpoint       {rbp}

 

1 Receive-Job               {rcjb}

 

1 Remove-PSDrive            {rdr}

 

2 Rename-Item               {ren, rni}

 

1 Remove-Job                {rjb}

 

1 Remove-Module             {rmo}

 

1 Rename-ItemProperty       {rnp}

 

1 Remove-ItemProperty       {rp}

 

1 Remove-PSSession          {rsn}

 

1 Remove-PSSnapin           {rsnp}

 

1 Remove-Variable           {rv}

 

1 Resolve-Path              {rvpa}

 

1 Remove-WMIObject          {rwmi}

 

1 Start-Job                 {sajb}

 

1 Set-Alias                 {sal}

 

2 Start-Process             {saps, start}

 

1 Start-Service             {sasv}

 

1 Set-PSBreakpoint          {sbp}

 

1 Set-Content               {sc}

 

1 Select-Object             {select}

 

2 Set-Variable              {set, sv}

 

1 Set-Item                  {si}

 

1 Start-Sleep               {sleep}

 

1 Sort-Object               {sort}

 

1 Set-ItemProperty          {sp}

 

1 Stop-Job                  {spjb}

 

1 Stop-Service              {spsv}

 

1 Set-WMIInstance           {swmi}

 

1 Tee-Object                {tee}

 

1 Wait-Job                  {wjb}

 

Measure-Object

オブジェクトのプロパティを集計することができます。

PS C:\> Get-Item * | Measure-Object Length -Sum -Average -Maximum -Minimum

 

 

 

Count    : 2

 

Average  : 17

 

Sum      : 34

 

Maximum  : 24

 

Minimum  : 10

 

Property : Length

 

Sort-Object

オブジェクトを特定のプロパティでソートすることができます。規定で昇順、-descendingオプションで降順にソートします。

PS C:\> Get-Process | Sort-Object CPU -descending

 

 

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName

 

-------  ------    -----      ----- -----   ------     -- -----------

 

854      67   110004     121412   433   137.44   3980 WindowsLiveWriter

 

1688      31    49796      77232   439    28.76   3472 chrome

 

832      33    24404      40776   229    10.12   2408 explorer

 

472      18    45452      51656   145     9.45   3508 Dropbox

 

605      30    21368      53484   322     9.25   4108 POWERPNT

 

419      12    50432      54608   190     4.76   5648 powershell

 

125       9    43616      49224   152     4.25   3156 chrome

 

125      10    64060      64848   187     4.03   3900 chrome

 

135       7     4400      11280    73     3.95   5880 conhost

 

125       8    29068      32984   163     2.42   3956 chrome

 

273       9     5824       8980    93     2.24   2820 avgtray

 

126       8    24088      30220   157     1.97   3760 chrome

 

124       8    24772      29988   152     1.82   3880 chrome

 

124       8    26668      30644   157     1.75   3772 chrome

 

492      16     6184      17844   119     1.64   3496 ApplePhotoStreams

 

129       8    23876      29312   154     1.57   3836 chrome

 

125       8    23452      27468   152     1.51   3848 chrome

 

124       8    22188      26532   154     1.45   3940 chrome

 

124       8    23096      26292   152     1.39   3964 chrome

 

124       8    23184      26512   152     1.34   3736 chrome

 

124       8    22280      26912   150     1.29   3816 chrome

 

124       8    22280      26812   150     1.25   3784 chrome

 

124       7    22016      25996   149     1.22   3804 chrome

 

125       8    23140      26180   151     1.16   3720 chrome

 

124       8    23036      25912   152     1.15   3872 chrome

 

124       8    23168      26824   152     0.97   3916 chrome

 

218      10     5684      10760   126     0.86   2612 IMECMNT

 

181       9     3320       7112    59     0.61   2312 taskhost

 

352      13     4512      12448   101     0.59   1768 APSDaemon

 

57       4     5796      12732    68     0.58   3452 xkeymacs

 

161       9     4308      11968   108     0.45   3488 iCloudServices

 

91       5     1484       5596    59     0.40   3332 wuauclt

 

102       6     2764       6084    64     0.28   2744 VBoxTray

 

79       4     1328       4624    55     0.13   2400 dwm

 

168       6     1676       5596    39            2560 svchost

 

618       0      272       1956   106               4 System

 

640      10    30120       2780    91             280 avgrsx

 

248      13     3700       8264    41            1756 svchost

 

383      15     5832      12616    56            1340 svchost

 

1344      42    20556      33876   169            1184 svchost

 

314      24    11768      11672    49            1580 svchost

 

640      23    12276      13908    70            1432 svchost

 

50       3      600       2388    26             260 WLIDSVCM

 

335      10     4140      10828    54            1944 WLIDSVC

 

738      13     4260      10204    35             692 lsass

 

256       8     4664       5256    83            2944 wmpnetwk

 

129       4    17996        328   153             312 avgcsrvx

 

107       5     1272       3872    30             952 VBoxService

 

115       4     2036       5680    46             632 winlogon

 

80       5     1336       4312    40             588 wininit

 

505      13    53764      60032   117            1144 svchost

 

196       7     2524       6212    34            5308 OSE

 

91       5     3584       7736    44            1240 mscorsvw

 

468       6     1308       4748    49             544 csrss

 

152       5     4424      12096    34            1936 OSPPSVC

 

106       6     1416       4332    26            1720 mDNSResponder

 

54       3      732       2968    19            1812 IMEDICTUPDATE

 

0       0        0         24     0               0 Idle

 

151       4     1240       3064    14             700 lsm

 

562       8     1456      12080    77             580 csrss

 

359       7     2660       6616    31             888 svchost

 

91       5     1736       4508    21             792 svchost

 

572      14    13980      15040    76            1056 svchost

 

293       8     2780       6064    25            1004 svchost

 

285      10     4304       9020    55            1544 spoolsv

 

649      19    25460      18100   112            3020 SearchIndexer

 

605      11     6200      13632    73            1676 avgwdsvc

 

29       1      220        772     4             236 smss

 

220       7     4228       7056    29             672 services

 

ForEach-Object

オブジェクト1つ1つに対して処理を実施できます。Where-Objectで抜き出したオブジェクトに対してForEach-Objectで処理をする…というのがよくあるパターンです。ForEach-Object内では$_が現在のオブジェクトを表します。

PS C:\> Get-Item * | ForEach-Object { $_.Name.ToLower() }

 

perflogs

 

program files

 

users

 

windows

 

autoexec.bat

 

config.sys

 

ディレクトリ移動(Get-Location, Set-Location, Push-Location, Pop-Location)

Get-Locationでカレントディレクトリの表示、Set-Locationで移動。Push-Locationでも移動できますがその場合、Pop-Locationで戻ることができます。

PS C:\> Get-Location

 

 

Path

 

----

 

C:\

 

 

 

PS C:\> Set-Location C:\Users

 

PS C:\Users> Push-Location C:\Windows\System32

 

PS C:\Windows\System32> Push-Location "C:\Program Files"

 

PS C:\Program Files> Pop-Location

 

PS C:\Windows\System32> Pop-Location

 

PS C:\Users> Pop-Location

 

PS C:\Users>

 

変数

宣言、命名規則

宣言は必要ありません。$で始まり2文字目は英数字かアンダースコアが使えます。それ以外の文字は${}の中に記述すれば使えます。

PS C:\> $hoge = "sample"

 

PS C:\> ${任意の文字} = "sample2"

 

PS C:\> $hoge

 

sample

 

PS C:\> ${任意の文字}

 

sample2

 

PS C:\>

 

型

自動的に型が決定されます。GetType()で型が確認できます。明示的に型を宣言することもできます。

PS C:\> "文字列".GetType()

 

 

IsPublic IsSerial Name                                     BaseType

 

-------- -------- ----                                     --------

 

True     True     String                                   System.Object

 

 

 

PS C:\> (10).GetType()

 

 

IsPublic IsSerial Name                                     BaseType

 

-------- -------- ----                                     --------

 

True     True     Int32                                    System.ValueType

 

 

 

PS C:\> $hoge = 10

 

PS C:\> $hoge.GetType()

 

 

IsPublic IsSerial Name                                     BaseType

 

-------- -------- ----                                     --------

 

True     True     Int32                                    System.ValueType

 

 

 

PS C:\> [String]$hoge = 10

 

PS C:\> $hoge.GetType()

 

 

IsPublic IsSerial Name                                     BaseType

 

-------- -------- ----                                     --------

 

True     True     String                                   System.Object

 

配列

「,」あるいは「@」を使って配列を作成できます。

PS C:\> $array = 1, 2, 3

 

PS C:\> $array

 

1

 

2

 

3

 

PS C:\> $array[0]

 

1

 

PS C:\> $array = @(1; 1+1; 3)

 

PS C:\> $array

 

1

 

2

 

3

 

PS C:\> $emptyarray = @()

 

PS C:\> $emptyarray

 

PS C:\> $emptyarray.length

 

0

 

要素追加

+=で要素を追加できます。

PS C:\> $array = @(1; 2; 3)

 

PS C:\> $array

 

1

 

2

 

3

 

PS C:\> $array += 4

 

PS C:\> $array

 

1

 

2

 

3

 

4

 

 

連想配列

@{}で連想配列を作れます。

PS C:\> $countries = @{japan = "日本"}

 

PS C:\> $countries["china"] = "中国"

 

PS C:\> $countries.india = "インド"

 

PS C:\> $countries

 

 

Name                           Value

 

----                           -----

 

japan                          日本

 

china                          中国

 

india                          インド

 

PSドライブ

ファイルシステム以外にも複数のものがドライブとして用意されている。Get-PSDriveで一覧を確認し、Set-Locationで簡単に移動できる。

PS C:\> Get-PSDrive

 

 

Name           Used (GB)     Free (GB) Provider      Root                                CurrentLoc

 

ation

 

----           ---------     --------- --------      ----                                ----------

 

Alias                                  Alias

 

C                  17.10          2.80 FileSystem    C:\

 

cert                                   Certificate   \

 

D                    .04               FileSystem    D:\

 

E                 144.65          3.60 FileSystem    E:\

 

Env                                    Environment

 

Function                               Function

 

HKCU                                   Registry      HKEY_CURRENT_USER

 

HKLM                                   Registry      HKEY_LOCAL_MACHINE

 

Variable                               Variable

 

WSMan                                  WSMan

 

 

 

PS C:\> Set-Location HKLM:

 

PS HKLM:\> cd .\SOFTWARE

 

PS HKLM:\SOFTWARE> ls

 

 

 

Hive: HKEY_LOCAL_MACHINE\SOFTWARE

 

 

 

SKC  VC Name                           Property

 

---  -- ----                           --------

 

4   0 Apple Inc.                     {}

 

1   0 ATI Technologies               {}

 

1   0 Avg                            {}

 

516   0 Classes                        {}

 

6   0 Clients                        {}

 

1   0 Intel                          {}

 

156   0 Microsoft                      {}

 

2   0 MozillaPlugins                 {}

 

2   0 ODBC                           {}

 

1   0 Oracle                         {}

 

1   0 Policies                       {}

 

1   0 Quest Software                 {}

 

0  11 RegisteredApplications         {Windows Address Book, Paint, Windows Search, Windows Dis...

 

1   0 Sonic                          {}

 

WhatIf

実行前に何が行われるのかの確認を行うことができる。

PS C:\> Move-Item windows windows2 -WhatIf

 

WhatIf: 対象 "項目: C:\windows 移動先: C:\windows2" に対して操作 "ディレクトリの移動" を実行していま

 

す。

 

Start-Transcript, Stop-Transcript

シェル上のやり取りをすべてファイルに記録できる。

PS C:\> Start-Transcript

 

トランスクリプトが開始されました。出力ファイル: C:\Users\ebi\Documents\PowerShell_transcript.201203

 

04221123.txt

 

PS C:\> Get-Item *

 

 

 

ディレクトリ: C:\

 

 

 

Mode                LastWriteTime     Length Name

 

----                -------------     ------ ----

 

d----        2009/07/14     11:37            PerfLogs

 

d-r--        2012/02/23     22:33            Program Files

 

d-r--        2012/01/11     23:31            Users

 

d----        2012/02/20     23:36            Windows

 

-a---        2009/06/11      6:42         24 autoexec.bat

 

-a---        2009/06/11      6:42         10 config.sys

 

 

 

PS C:\> Stop-Transcript

 

トランスクリプトが停止されました。出力ファイル: C:\Users\ebi\Documents\PowerShell_transcript.201203

 

04221123.txt

 

PS C:\> type C:\Users\ebi\Documents\PowerShell_transcript.20120304221123.txt

 

**********************

 

Windows PowerShell トランスクリプト開始

 

開始時刻: 20120304221123

 

ユーザー名  : windows7onMAC\ebi

 

コンピューター    : WINDOWS7ONMAC (Microsoft Windows NT 6.1.7600.0)

 

**********************

 

トランスクリプトが開始されました。出力ファイル: C:\Users\ebi\Documents\PowerShell_transcript.201203

 

04221123.txt

 

PS C:\> Get-Item *

 

 

 

ディレクトリ: C:\

 

 

 

Mode                LastWriteTime     Length Name

 

----                -------------     ------ ----

 

d----        2009/07/14     11:37            PerfLogs

 

d-r--        2012/02/23     22:33            Program Files

 

d-r--        2012/01/11     23:31            Users

 

d----        2012/02/20     23:36            Windows

 

-a---        2009/06/11      6:42         24 autoexec.bat

 

-a---        2009/06/11      6:42         10 config.sys

 

 

 

PS C:\> Stop-Transcript

 

**********************

 

Windows PowerShell トランスクリプト終了

 

終了時刻: 20120304221138

 

**********************

 

PS C:\>

 

Get-WMIObject

WMIの呼び出しもコマンドレットで簡単に行える。

PS C:\>

 

PS C:\> Get-WmiObject -class Win32_DiskDrive

 

 

 

Partitions : 2

 

DeviceID   : \\.\PHYSICALDRIVE0

 

Model      : VBOX HARDDISK ATA Device

 

Size       : 21467980800

 

Caption    : VBOX HARDDISK ATA Device

 

.NET Frameworkのクラスの利用

オブジェクト生成

PS C:\> $webclient = New-Object System.Net.WebClient

 

PS C:\> $webclient.DownloadString(http://ebi.dyndns.biz)

 

静的メソッドへのアクセス

PS C:\> [System.Console]::WriteLine("hoge")

 

hoge

 

アセンブリのロード

PS C:\> [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

 

 

GAC    Version        Location

 

---    -------        --------

 

True   v2.0.50727     C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\Syst...

 

ロードされているアセンブリの確認

PS C:\> ([AppDomain]::CurrentDomain).GetAssemblies() | Format-List

 

 

 

CodeBase               : file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

 

FullName               : mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e08

 

9

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll

 

ManifestModule         : CommonLanguageRuntimeLibrary

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.ConsoleHost/1.0.

 

0.0__31bf3856ad364e35/Microsoft.PowerShell.ConsoleHost.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.ConsoleHost/1.0.

 

0.0__31bf3856ad364e35/Microsoft.PowerShell.ConsoleHost.dll

 

FullName               : Microsoft.PowerShell.ConsoleHost, Version=1.0.0.0, Culture=neutral, Public

 

KeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.ConsoleHost\1.0.0.0__31b

 

f3856ad364e35\Microsoft.PowerShell.ConsoleHost.dll

 

ManifestModule         : Microsoft.PowerShell.ConsoleHost.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Management.Automation/1.0.0.0_

 

_31bf3856ad364e35/System.Management.Automation.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Management.Automation/1.0.0.0_

 

_31bf3856ad364e35/System.Management.Automation.dll

 

FullName               : System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyT

 

oken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf385

 

6ad364e35\System.Management.Automation.dll

 

ManifestModule         : System.Management.Automation.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/Syst

 

em.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/Syst

 

em.dll

 

FullName               : System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll

 

ManifestModule         : System.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Diagnos

 

tics/1.0.0.0__31bf3856ad364e35/Microsoft.PowerShell.Commands.Diagnostics.d

 

ll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Diagnos

 

tics/1.0.0.0__31bf3856ad364e35/Microsoft.PowerShell.Commands.Diagnostics.d

 

ll

 

FullName               : Microsoft.PowerShell.Commands.Diagnostics, Version=1.0.0.0, Culture=neutra

 

l, PublicKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Diagnostics\1.0

 

.0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Diagnostics.dll

 

ManifestModule         : Microsoft.PowerShell.Commands.Diagnostics.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Configuration.Install/2.0.0.0_

 

_b03f5f7f11d50a3a/System.Configuration.Install.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Configuration.Install/2.0.0.0_

 

_b03f5f7f11d50a3a/System.Configuration.Install.dll

 

FullName               : System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyT

 

oken=b03f5f7f11d50a3a

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Configuration.Install\2.0.0.0__b03f5f7

 

f11d50a3a\System.Configuration.Install.dll

 

ManifestModule         : System.Configuration.Install.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.WSMan.Management/1.0.0.0__3

 

1bf3856ad364e35/Microsoft.WSMan.Management.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.WSMan.Management/1.0.0.0__3

 

1bf3856ad364e35/Microsoft.WSMan.Management.dll

 

FullName               : Microsoft.WSMan.Management, Version=1.0.0.0, Culture=neutral, PublicKeyTok

 

en=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.WSMan.Management\1.0.0.0__31bf3856a

 

d364e35\Microsoft.WSMan.Management.dll

 

ManifestModule         : Microsoft.WSMan.Management.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.WSMan.Runtime/1.0.0.0__31bf

 

3856ad364e35/Microsoft.WSMan.Runtime.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.WSMan.Runtime/1.0.0.0__31bf

 

3856ad364e35/Microsoft.WSMan.Runtime.dll

 

FullName               : Microsoft.WSMan.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=

 

31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.WSMan.Runtime\1.0.0.0__31bf3856ad36

 

4e35\Microsoft.WSMan.Runtime.dll

 

ManifestModule         : Microsoft.WSMan.Runtime.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c5619

 

34e089/System.Transactions.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c5619

 

34e089/System.Transactions.dll

 

FullName               : System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a

 

5c561934e089

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_32\System.Transactions\2.0.0.0__b77a5c561934e089\S

 

ystem.Transactions.dll

 

ManifestModule         : System.Transactions.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Utility

 

/1.0.0.0__31bf3856ad364e35/Microsoft.PowerShell.Commands.Utility.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Utility

 

/1.0.0.0__31bf3856ad364e35/Microsoft.PowerShell.Commands.Utility.dll

 

FullName               : Microsoft.PowerShell.Commands.Utility, Version=1.0.0.0, Culture=neutral, P

 

ublicKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility\1.0.0.0

 

__31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.dll

 

ManifestModule         : Microsoft.PowerShell.Commands.Utility.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Managem

 

ent/1.0.0.0__31bf3856ad364e35/Microsoft.PowerShell.Commands.Management.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Managem

 

ent/1.0.0.0__31bf3856ad364e35/Microsoft.PowerShell.Commands.Management.dll

 

FullName               : Microsoft.PowerShell.Commands.Management, Version=1.0.0.0, Culture=neutral

 

, PublicKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Management\1.0.

 

0.0__31bf3856ad364e35\Microsoft.PowerShell.Commands.Management.dll

 

ManifestModule         : Microsoft.PowerShell.Commands.Management.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Management/2.0.0.0__b03f5f7f11

 

d50a3a/System.Management.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Management/2.0.0.0__b03f5f7f11

 

d50a3a/System.Management.dll

 

FullName               : System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f

 

7f11d50a3a

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Management\2.0.0.0__b03f5f7f11d50a3a\S

 

ystem.Management.dll

 

ManifestModule         : System.Management.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.ServiceProcess/2.0.0.0__b03f5f

 

7f11d50a3a/System.ServiceProcess.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.ServiceProcess/2.0.0.0__b03f5f

 

7f11d50a3a/System.ServiceProcess.dll

 

FullName               : System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b0

 

3f5f7f11d50a3a

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.ServiceProcess\2.0.0.0__b03f5f7f11d50a

 

3a\System.ServiceProcess.dll

 

ManifestModule         : System.ServiceProcess.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Security/1.0.0.0

 

__31bf3856ad364e35/Microsoft.PowerShell.Security.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Security/1.0.0.0

 

__31bf3856ad364e35/Microsoft.PowerShell.Security.dll

 

FullName               : Microsoft.PowerShell.Security, Version=1.0.0.0, Culture=neutral, PublicKey

 

Token=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Security\1.0.0.0__31bf38

 

56ad364e35\Microsoft.PowerShell.Security.dll

 

ManifestModule         : Microsoft.PowerShell.Security.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.ConsoleHost.reso

 

urces/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.ConsoleHost.resourc

 

es.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.ConsoleHost.reso

 

urces/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.ConsoleHost.resourc

 

es.dll

 

FullName               : Microsoft.PowerShell.ConsoleHost.resources, Version=1.0.0.0, Culture=ja, P

 

ublicKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.ConsoleHost.resources\1.

 

0.0.0_ja_31bf3856ad364e35\Microsoft.PowerShell.ConsoleHost.resources.dll

 

ManifestModule         : Microsoft.PowerShell.ConsoleHost.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/

 

System.Xml.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/

 

System.Xml.dll

 

FullName               : System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e

 

089

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.X

 

ml.dll

 

ManifestModule         : System.Xml.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.DirectoryServices/2.0.0.0__b03

 

f5f7f11d50a3a/System.DirectoryServices.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.DirectoryServices/2.0.0.0__b03

 

f5f7f11d50a3a/System.DirectoryServices.dll

 

FullName               : System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken

 

=b03f5f7f11d50a3a

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.DirectoryServices\2.0.0.0__b03f5f7f11d

 

50a3a\System.DirectoryServices.dll

 

ManifestModule         : System.DirectoryServices.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Management.Automation.resource

 

s/1.0.0.0_ja_31bf3856ad364e35/System.Management.Automation.resources.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Management.Automation.resource

 

s/1.0.0.0_ja_31bf3856ad364e35/System.Management.Automation.resources.dll

 

FullName               : System.Management.Automation.resources, Version=1.0.0.0, Culture=ja, Publi

 

cKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Management.Automation.resources\1.0.0.

 

0_ja_31bf3856ad364e35\System.Management.Automation.resources.dll

 

ManifestModule         : System.Management.Automation.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.WSMan.Management.resources/

 

1.0.0.0_ja_31bf3856ad364e35/Microsoft.WSMan.Management.resources.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.WSMan.Management.resources/

 

1.0.0.0_ja_31bf3856ad364e35/Microsoft.WSMan.Management.resources.dll

 

FullName               : Microsoft.WSMan.Management.resources, Version=1.0.0.0, Culture=ja, PublicK

 

eyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.WSMan.Management.resources\1.0.0.0_

 

ja_31bf3856ad364e35\Microsoft.WSMan.Management.resources.dll

 

ManifestModule         : Microsoft.WSMan.Management.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll

 

FullName               : mscorlib.resources, Version=2.0.0.0, Culture=ja, PublicKeyToken=b77a5c5619

 

34e089

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll

 

ManifestModule         : mscorlib.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Security.resourc

 

es/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.Security.resources.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Security.resourc

 

es/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.Security.resources.dll

 

FullName               : Microsoft.PowerShell.Security.resources, Version=1.0.0.0, Culture=ja, Publ

 

icKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Security.resources\1.0.0

 

.0_ja_31bf3856ad364e35\Microsoft.PowerShell.Security.resources.dll

 

ManifestModule         : Microsoft.PowerShell.Security.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/S

 

ystem.Data.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/S

 

ystem.Data.dll

 

FullName               : System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934

 

e089

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Da

 

ta.dll

 

ManifestModule         : System.Data.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Utility

 

.resources/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.Commands.Utili

 

ty.resources.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Utility

 

.resources/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.Commands.Utili

 

ty.resources.dll

 

FullName               : Microsoft.PowerShell.Commands.Utility.resources, Version=1.0.0.0, Culture=

 

ja, PublicKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Utility.resourc

 

es\1.0.0.0_ja_31bf3856ad364e35\Microsoft.PowerShell.Commands.Utility.resou

 

rces.dll

 

ManifestModule         : Microsoft.PowerShell.Commands.Utility.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.resources/2.0.0.0_ja_b77a5c561

 

934e089/System.resources.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.resources/2.0.0.0_ja_b77a5c561

 

934e089/System.resources.dll

 

FullName               : System.resources, Version=2.0.0.0, Culture=ja, PublicKeyToken=b77a5c561934

 

e089

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.resources\2.0.0.0_ja_b77a5c561934e089\

 

System.resources.dll

 

ManifestModule         : System.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Managem

 

ent.resources/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.Commands.Ma

 

nagement.resources.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/Microsoft.PowerShell.Commands.Managem

 

ent.resources/1.0.0.0_ja_31bf3856ad364e35/Microsoft.PowerShell.Commands.Ma

 

nagement.resources.dll

 

FullName               : Microsoft.PowerShell.Commands.Management.resources, Version=1.0.0.0, Cultu

 

re=ja, PublicKeyToken=31bf3856ad364e35

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0

 

Location               : C:\Windows\assembly\GAC_MSIL\Microsoft.PowerShell.Commands.Management.reso

 

urces\1.0.0.0_ja_31bf3856ad364e35\Microsoft.PowerShell.Commands.Management

 

.resources.dll

 

ManifestModule         : Microsoft.PowerShell.Commands.Management.resources.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7

 

f11d50a3a/System.Configuration.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7

 

f11d50a3a/System.Configuration.dll

 

FullName               : System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03

 

f5f7f11d50a3a

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3

 

a\System.Configuration.dll

 

ManifestModule         : System.Configuration.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

 

CodeBase               : file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50

 

a3a/System.Drawing.dll

 

EntryPoint             :

 

EscapedCodeBase        : file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50

 

a3a/System.Drawing.dll

 

FullName               : System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f1

 

1d50a3a

 

GlobalAssemblyCache    : True

 

HostContext            : 0

 

ImageFileMachine       :

 

ImageRuntimeVersion    : v2.0.50727

 

Location               : C:\Windows\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\Syst

 

em.Drawing.dll

 

ManifestModule         : System.Drawing.dll

 

MetadataToken          :

 

PortableExecutableKind :

 

ReflectionOnly         : False

 

CSVファイルのエクスポート、インポート

PS C:\> Get-Item * | Export-Csv c:\tmp\items.csv

 

PS C:\> $items = Import-csv C:\tmp\items.csv

 

PS C:\> $items[0]

 

 

 

PSPath            : Microsoft.PowerShell.Core\FileSystem::C:\PerfLogs

 

PSParentPath      : Microsoft.PowerShell.Core\FileSystem::C:\

 

PSChildName       : PerfLogs

 

PSDrive           : C

 

PSProvider        : Microsoft.PowerShell.Core\FileSystem

 

PSIsContainer     : True

 

BaseName          : PerfLogs

 

Mode              : d----

 

Name              : PerfLogs

 

Parent            :

 

Exists            : True

 

Root              : C:\

 

FullName          : C:\PerfLogs

 

Extension         :

 

CreationTime      : 2009/07/14 11:37:05

 

CreationTimeUtc   : 2009/07/14 2:37:05

 

LastAccessTime    : 2009/07/14 11:37:05

 

LastAccessTimeUtc : 2009/07/14 2:37:05

 

LastWriteTime     : 2009/07/14 11:37:05

 

LastWriteTimeUtc  : 2009/07/14 2:37:05

 

Attributes        : Directory

 

XMLファイルのエクスポート、インポート

PS C:\> Get-Item * | Export-Clixml c:\tmp\items.xml

 

PS C:\> $items = Import-Clixml C:\tmp\items.xml

 

PS C:\> $items[0]

 

 

 

ディレクトリ: C:\

 

 

 

Mode                LastWriteTime     Length Name

 

----                -------------     ------ ----

 

d----        2009/07/14     11:37            PerfLogs

 

 

スクリプト内でスクリプトが置かれているディレクトリを取得

$here = Split-Path -Parent $MyInvocation.MyCommand.Path

C#で型を定義

※型を定義する方法 [PS Advent Calendar ‘12] - PowerShell Scripting Weblogから引用しています。

Add-Type-TypeDefinition@"     namespace Winscript     {         public enum DriveType         {             Unknown,NoRootDirectory,RemovableDisk,LocalDisk,NetworkDrive,CompactDisc,RAMDisk         }         public class Drive         {             public string Name {get;set;}             public string VolumeName {get;set;}             public DriveType Type{get;set;}             public long Size  {get;set;}             public long FreeSpace  {get;set;}             public long UsedSpace  {get;set;}             public string RootPath {get;set;}         }     } “@ -LanguageCSharpVersion3

Add-Type -Namespace Winscript -Name Man -MemberDefinition @”     public int Age {get;set;}     public string Name {get;set;} “@ -Language CSharpVersion3

その他

- Office365へのPowerShell接続時にはWinHttpを使用しています。
- PowerShellで再起動を含めた処理の自動化
- PowerShellを使ってExcelできちんと開けるCSVファイルを作成する方法
- PowerShellでxmlファイルを読む方法
- PowerShell 3.0 OS基本設定
- ローカルの管理者権限があるかどうかを確認する
- PowerShellで簡単に集計する方法
- PowerShellでOSの基本情報を取得する