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

Get-Command

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

PSC:\>Get-Command

 

 

CommandTypeNameDefinition

 

 

Alias%ForEach-Object

 

Alias?Where-Object

 

FunctionA:Set-LocationA:

 

AliasacAdd-Content

 

CmdletAdd-ComputerAdd-Computer[-DomainName][

 

CmdletAdd-ContentAdd-Content[-Path][-Value...

 

CfmidnldesttrでフィルタリングすAるdこdと-でH探iすsのtもoいrいyと思います。Add-History[[-InputObject]

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 でコマンドレットのヘルプを表示できます。

PSC:\>Get-HelpGet-Item

 

 

名前

 

Get-Item

 

 

概要

 

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

 

 

 

構文

 

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

 

string>][-Force][-Includestring[]>][-UseTransaction][]

 

 

Get-Item[-Path]string[]>[-Credential][-Excludestring[]>][-Filterstring

 

>][-Force][-Includestring[]>][-UseTransaction][]

 

 

 

説明

 

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

 

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

 

 

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

 

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

 

 

 

関連するリンク

 

Onlineversion: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-helpGet-Item-examples".

 

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

 

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

 

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

PSC:\>Get-Help-fullGet-Item

 

 

名前

 

Get-Item

 

 

概要

 

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

 

 

構文

 

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

 

string>][-Force][-Includestring[]>][-UseTransaction][]

 

 

Get-Item[-Path]string[]>[-Credential][-Excludestring[]>][-Filterstring

 

>][-Force][-Includestring[]>][-UseTransaction][]

 

 

 

説明

 

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

 

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

 

 

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

 

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

 

 

 

パラメーター

 

-Credential

 

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

 

です。

 

 

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

 

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

 

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

 

 

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

 

ません。

 

 

必須false

 

位置named

 

既定値

 

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

 

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

 

 

-Excludestring[]>

 

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

 

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

 

 

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

 

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

 

 

必須false

 

位置named

 

既定値

 

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

 

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

 

 

-Filterstring>

 

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

 

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

 

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

 

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

 

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

 

 

必須false

 

位置named

 

既定値

 

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

 

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

 

 

-Force[]

 

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

 

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

 

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

 

 

必須false

 

位置named

 

既定値

 

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

 

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

 

 

-Includestring[]>

 

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

 

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

 

 

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

 

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

 

 

必須false

 

位置named

 

既定値

 

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

 

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

 

 

-LiteralPathstring[]>

 

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

 

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

 

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

 

 

必須true

 

位置1

 

既定値

 

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

 

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

 

 

-Pathstring[]>

 

項目のパスを指定します。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-helpabout_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:\

 

 

ModeLastWriteTimeLengthName

 

 

d----7/26/200610:01AMps-test

 

 

 

説明

 

 

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

 

内容ではありません)。

 

 

 

 

 

 

例2

 

 

C:\PS>get-item

 

 

Directory:C:\ps-test

 

 

ModeLastWriteTimeLengthName

 

 

d----7/26/20069:29AMLogs

 

d----7/26/20069:26AMRecs

 

-a---7/26/20069:28AM80date.csv

 

-a---7/26/200610:01AM30filenoext

 

-a---7/26/20069:30AM11472process.doc

 

-a---7/14/200610:47AM30test.txt

 

 

 

説明

 

 

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

 

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

 

 

 

 

 

 

例3

 

 

C:\PS>get-itemC:\

 

 

 

説明

 

 

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

 

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

 

 

 

 

 

 

例4

 

 

C:\PS>get-itemC:\*

 

 

 

説明

 

 

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

 

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

 

 

WindowsPowerShellでは、従来のではなく、単一のアスタリスクを使用して内容を取得します

 

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

 

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

 

 

 

 

 

 

例5

 

 

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

 

 

 

説明

 

 

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

 

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

 

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

 

 

 

 

 

 

例6

 

 

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

 

 

 

説明

 

 

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

 

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

 

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

 

 

 

 

 

 

例7

 

 

C:\PS>get-itemc:\Windows\*-include-excludew*

 

 

 

説明

 

 

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

 

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

 

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

 

 

 

 

 

 

 

関連するリンク

 

Onlineversion: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の世界です。パイプでオブジェクトを渡すことが多いでしょう。

PSC:\>Get-Itemc:\|Get-Member

 

 

 

TypeName:System.IO.DirectoryInfo

 

 

NameMemberTypeDefinition

 

 

ModeCodePropertySystem.StringMode{get=Mode;}

 

CreateMethodSystem.VoidCreate(System.Security.AccessControl.Direct...

 

CreateObjRefMethodSystem.Runtime.Remoting.ObjRefCreateObjRef(typereques...

 

CreateSubdirectoryMethodSystem.IO.DirectoryInfoCreateSubdirectory(stringpath)...

 

DeleteMethodSystem.VoidDelete(),System.VoidDelete(boolrecursive)

 

EqualsMethodboolEquals(System.Objectobj)

 

GetAccessControlMethodSystem.Security.AccessControl.DirectorySecurityGetAcce...

 

GetDirectoriesMethodSystem.IO.DirectoryInfo[]GetDirectories(stringsearchP...

 

GetFilesMethodSystem.IO.FileInfo[]GetFiles(stringsearchPattern),Sy...

 

GetFileSystemInfosMethodSystem.IO.FileSystemInfo[]GetFileSystemInfos(stringse...

 

GetHashCodeMethodintGetHashCode()

 

GetLifetimeServiceMethodSystem.ObjectGetLifetimeService()

 

GetObjectDataMethodSystem.VoidGetObjectData(System.Runtime.Serialization....

 

GetTypeMethodtypeGetType()

 

InitializeLifetimeServiceMethodSystem.ObjectInitializeLifetimeService()

 

MoveToMethodSystem.VoidMoveTo(stringdestDirName)

 

RefreshMethodSystem.VoidRefresh()

 

SetAccessControlMethodSystem.VoidSetAccessControl(System.Security.AccessCont...

 

ToStringMethodstringToString()

 

PSChildNameNotePropertySystem.StringPSChildName=C:\

 

PSDriveNotePropertySystem.Management.Automation.PSDriveInfoPSDrive=C

 

PSIsContainerNotePropertySystem.BooleanPSIsContainer=True

 

PSParentPathNotePropertySystem.StringPSParentPath=

 

PSPathNotePropertySystem.StringPSPath=Microsoft.PowerShell.Core\FileSyst...

 

PSProviderNotePropertySystem.Management.Automation.ProviderInfoPSProvider=Mi...

 

AttributesPropertySystem.IO.FileAttributesAttributes{get;set;}

 

CreationTimePropertySystem.DateTimeCreationTime{get;set;}

 

CreationTimeUtcPropertySystem.DateTimeCreationTimeUtc{get;set;}

 

ExistsPropertySystem.BooleanExists{get;}

 

ExtensionPropertySystem.StringExtension{get;}

 

FullNamePropertySystem.StringFullName{get;}

 

LastAccessTimePropertySystem.DateTimeLastAccessTime{get;set;}

 

LastAccessTimeUtcPropertySystem.DateTimeLastAccessTimeUtc{get;set;}

 

LastWriteTimePropertySystem.DateTimeLastWriteTime{get;set;}

 

LastWriteTimeUtcPropertySystem.DateTimeLastWriteTimeUtc{get;set;}

 

NamePropertySystem.StringName{get;}

 

ParentPropertySystem.IO.DirectoryInfoParent{get;}

 

RootPropertySystem.IO.DirectoryInfoRoot{get;}

 

BaseNameScriptPropertySystem.ObjectBaseName{get=$this.Name;}

 

Format-List

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

PSC:\>Get-Item|Format-List

 

 

 

ディレクトリ:C:\

 

 

 

 

Name:PerfLogs

 

CreationTime:2009/07/1411:37:05

 

LastWriteTime:2009/07/1411:37:05

 

LastAccessTime:2009/07/1411:37:05

 

 

Name:ProgramFiles

 

CreationTime:2009/07/1411:37:05

 

LastWriteTime:2012/02/2322:33:31

 

LastAccessTime:2012/02/2322:33:31

 

 

Name:Users

 

CreationTime:2009/07/1411:37:05

 

LastWriteTime:2012/01/1123:31:26

 

LastAccessTime:2012/01/1123:31:26

 

 

Name:Windows

 

CreationTime:2009/07/1411:37:05

 

LastWriteTime:2012/02/2023:36:09

 

LastAccessTime:2012/02/2023:36:09

 

 

Name:autoexec.bat

 

Length:24

 

CreationTime:2009/07/1411:04:04

 

LastWriteTime:2009/06/116:42:20

 

LastAccessTime:2009/07/1411: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/1411:04:04

 

LastWriteTime:2009/06/116:42:20

 

LastAccessTime:2009/07/1411: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のテーブルで表示できます。しかもそこからフィルタもかけることができるので便利に使えるケースも多いと思います。

PSC:\>Get-Itemc:\|Get-Member|Out-GridView

 

image

Where-Object

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

PSC:\>Get-Process|Where-Object{$_.WS-ge50MB}

 

 

HandlesNPM(K)PM(K)WS(K)VM(M)CPU(s)IdProcessName

 

 

167830501007747643825.163472chrome

 

1251064060648481874.013900chrome

 

4721945448516521458.723508Dropbox

 

6053022308543923238.964108POWERPNT

 

5011352784589481171144svchost

 

8356010633211138842865.593980WindowsLiveWriter

 

Group-Object

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

PSC:\>Get-Alias|Group-ObjectDefinition

 

 

CountNameGroup

 

 

2ForEach-Object{%,foreach}

 

2Where-Object{?,where}

 

1Add-Content{ac}

 

1Add-PSSnapIn{asnp}

 

3Get-Content{cat,gc,type}

 

3Set-Location{cd,chdir,sl}

 

1Clear-Content{clc}

 

2Clear-Host{clear,cls}

 

1Clear-History{clhy}

 

1Clear-Item{cli}

 

1Clear-ItemProperty{clp}

 

1Clear-Variable{clv}

 

2Compare-Object{compare,diff}

 

3Copy-Item{copy,cp,cpi}

 

1Copy-ItemProperty{cpp}

 

1Convert-Path{cvpa}

 

1Disable-PSBreakpoint{dbp}

 

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

 

3Get-ChildItem{dir,gci,ls}

 

1Enable-PSBreakpoint{ebp}

 

2Write-Output{echo,write}

 

1Export-Alias{epal}

 

1Export-Csv{epcsv}

 

1Export-PSSession{epsn}

 

1Enter-PSSession{etsn}

 

1Exit-PSSession{exsn}

 

1Format-Custom{fc}

 

1Format-List{fl}

 

1Format-Table{ft}

 

1Format-Wide{fw}

 

1Get-Alias{gal}

 

1Get-PSBreakpoint{gbp}

 

1Get-Command{gcm}

 

1Get-PSCallStack{gcs}

 

1Get-PSDrive{gdr}

 

3Get-History{ghy,h,history}

 

1Get-Item{gi}

 

1Get-Job{gjb}

 

2Get-Location{gl,pwd}

 

1Get-Member{gm}

 

1Get-Module{gmo}

 

1Get-ItemProperty{gp}

 

2Get-Process{gps,ps}

 

1Group-Object{group}

 

1Get-PSSession{gsn}

 

1Get-PSSnapIn{gsnp}

 

1Get-Service{gsv}

 

1Get-Unique{gu}

 

1Get-Variable{gv}

 

1Get-WmiObject{gwmi}

 

1Invoke-Command{icm}

 

1Invoke-Expression{iex}

 

2Invoke-History{ihy,r}

 

1Invoke-Item{ii}

 

1Import-Alias{ipal}

 

1Import-Csv{ipcsv}

 

1Import-Module{ipmo}

 

1Import-PSSession{ipsn}

 

1powershell_ise.exe{ise}

 

1Invoke-WMIMethod{iwmi}

 

2Stop-Process{kill,spps}

 

1Out-Printer{lp}

 

1help{man}

 

1mkdir{md}

 

1Measure-Object{measure}

 

3Move-Item{mi,move,mv}

 

2New-PSDrive{mount,ndr}

 

1Move-ItemProperty{mp}

 

1New-Alias{nal}

 

1New-Item{ni}

 

1New-Module{nmo}

 

1New-PSSession{nsn}

 

1New-Variable{nv}

 

1Out-GridView{ogv}

 

1Out-Host{oh}

 

1Pop-Location{popd}

 

1Push-Location{pushd}

 

1Remove-PSBreakpoint{rbp}

 

1Receive-Job{rcjb}

 

1Remove-PSDrive{rdr}

 

2Rename-Item{ren,rni}

 

1Remove-Job{rjb}

 

1Remove-Module{rmo}

 

1Rename-ItemProperty{rnp}

 

1Remove-ItemProperty{rp}

 

1Remove-PSSession{rsn}

 

1Remove-PSSnapin{rsnp}

 

1Remove-Variable{rv}

 

1Resolve-Path{rvpa}

 

1Remove-WMIObject{rwmi}

 

1Start-Job{sajb}

 

1Set-Alias{sal}

 

2Start-Process{saps,start}

 

1Start-Service{sasv}

 

1Set-PSBreakpoint{sbp}

 

1Set-Content{sc}

 

1Select-Object{select}

 

2Set-Variable{set,sv}

 

1Set-Item{si}

 

1Start-Sleep{sleep}

 

1Sort-Object{sort}

 

1Set-ItemProperty{sp}

 

1Stop-Job{spjb}

 

1Stop-Service{spsv}

 

1Set-WMIInstance{swmi}

 

1Tee-Object{tee}

 

1Wait-Job{wjb}

 

Measure-Object

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

PSC:\>Get-Item|Measure-ObjectLength-Sum-Average-Maximum-Minimum

 

 

 

Count:2

 

Average:17

 

Sum:34

 

Maximum:24

 

Minimum:10

 

Property:Length

 

Sort-Object

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

PSC:\>Get-Process|Sort-ObjectCPU-descending

 

 

HandlesNPM(K)PM(K)WS(K)VM(M)CPU(s)IdProcessName

 

 

85467110004121412433137.443980WindowsLiveWriter

 

168831497967723243928.763472chrome

 

83233244044077622910.122408explorer

 

4721845452516561459.453508Dropbox

 

6053021368534843229.254108POWERPNT

 

4191250432546081904.765648powershell

 

125943616492241524.253156chrome

 

1251064060648481874.033900chrome

 

1357440011280733.955880conhost

 

125829068329841632.423956chrome

 

273958248980932.242820avgtray

 

126824088302201571.973760chrome

 

124824772299881521.823880chrome

 

124826668306441571.753772chrome

 

492166184178441191.643496ApplePhotoStreams

 

129823876293121541.573836chrome

 

125823452274681521.513848chrome

 

124822188265321541.453940chrome

 

124823096262921521.393964chrome

 

124823184265121521.343736chrome

 

124822280269121501.293816chrome

 

124822280268121501.253784chrome

 

124722016259961491.223804chrome

 

125823140261801511.163720chrome

 

124823036259121521.153872chrome

 

124823168268241520.973916chrome

 

218105684107601260.862612IMECMNT

 

181933207112590.612312taskhost

 

352134512124481010.591768APSDaemon

 

574579612732680.583452xkeymacs

 

16194308119681080.453488iCloudServices

 

91514845596590.403332wuauclt

 

102627646084640.282744VBoxTray

 

79413284624550.132400dwm

 

168616765596392560svchost

 

618027219561064System

 

6401030120278091280avgrsx

 

2481337008264411756svchost

 

38315583212616561340svchost

 

13444220556338761691184svchost

 

314241176811672491580svchost

 

640231227613908701432svchost

 

503600238826260WLIDSVCM

 

33510414010828541944WLIDSVC

 

7381342601020435692lsass

 

256846645256832944wmpnetwk

 

129417996328153312avgcsrvx

 

10751272387230952VBoxService

 

11542036568046632winlogon

 

8051336431240588wininit

 

5051353764600321171144svchost

 

196725246212345308OSE

 

91535847736441240mscorsvw

 

46861308474849544csrss

 

1525442412096341936OSPPSVC

 

106614164332261720mDNSResponder

 

5437322968191812IMEDICTUPDATE

 

0002400Idle

 

15141240306414700lsm

 

562814561208077580csrss

 

35972660661631888svchost

 

9151736450821792svchost

 

572141398015040761056svchost

 

293827806064251004svchost

 

2851043049020551544spoolsv

 

6491925460181001123020SearchIndexer

 

60511620013632731676avgwdsvc

 

2912207724236smss

 

22074228705629672services

 

ForEach-Object

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

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

 

perflogs

 

programfiles

 

users

 

windows

 

autoexec.bat

 

config.sys

 

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

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

PSC:\>Get-Location

 

 

Path

 

 

C:\

 

 

 

PSC:\>Set-LocationC:\Users

 

PSC:\Users>Push-LocationC:\Windows\System32

 

PSC:\Windows\System32>Push-Location"C:\ProgramFiles"

 

PSC:\ProgramFiles>Pop-Location

 

PSC:\Windows\System32>Pop-Location

 

PSC:\Users>Pop-Location

 

PSC:\Users>

 

変数

宣言、命名規則

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

PSC:\>$hoge="sample"

 

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

 

PSC:\>$hoge

 

sample

 

PSC:\>${任意の文字}

 

sample2

 

PSC:\>

 

型

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

PSC:\>"文字列".GetType()

 

 

IsPublicIsSerialNameBaseType

 

 

TrueTrueStringSystem.Object

 

 

 

PSC:\>(10).GetType()

 

 

IsPublicIsSerialNameBaseType

 

 

TrueTrueInt32System.ValueType

 

 

 

PSC:\>$hoge=10

 

PSC:\>$hoge.GetType()

 

 

IsPublicIsSerialNameBaseType

 

 

TrueTrueInt32System.ValueType

 

 

 

PSC:\>[String]$hoge=10

 

PSC:\>$hoge.GetType()

 

 

IsPublicIsSerialNameBaseType

 

 

TrueTrueStringSystem.Object

 

配列

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

PSC:\>$array=1,2,3

 

PSC:\>$array

 

1

 

2

 

3

 

PSC:\>$array[0]

 

1

 

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

 

PSC:\>$array

 

1

 

2

 

3

 

PSC:\>$emptyarray=@()

 

PSC:\>$emptyarray

 

PSC:\>$emptyarray.length

 

0

 

要素追加

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

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

 

PSC:\>$array

 

1

 

2

 

3

 

PSC:\>$array+=4

 

PSC:\>$array

 

1

 

2

 

3

 

4

 

 

連想配列

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

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

 

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

 

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

 

PSC:\>$countries

 

 

NameValue

 

 

japan日本

 

china中国

 

indiaインド

 

PSドライブ

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

PSC:\>Get-PSDrive

 

 

NameUsed(GB)Free(GB)ProviderRootCurrentLoc

 

ation

 

 

AliasAlias

 

C17.102.80FileSystemC:\

 

certCertificate

 

D.04FileSystemD:\

 

E144.653.60FileSystemE:\

 

EnvEnvironment

 

FunctionFunction

 

HKCURegistryHKEY_CURRENT_USER

 

HKLMRegistryHKEY_LOCAL_MACHINE

 

VariableVariable

 

WSManWSMan

 

 

 

PSC:\>Set-LocationHKLM:

 

PSHKLM:\>cd\SOFTWARE

 

PSHKLM:\SOFTWARE>ls

 

 

 

Hive:HKEY_LOCAL_MACHINE\SOFTWARE

 

 

 

SKCVCNameProperty

 

 

40AppleInc.{}

 

10ATITechnologies{}

 

10Avg{}

 

5160Classes{}

 

60Clients{}

 

10Intel{}

 

1560Microsoft{}

 

20MozillaPlugins{}

 

20ODBC{}

 

10Oracle{}

 

10Policies{}

 

10QuestSoftware{}

 

011RegisteredApplications{WindowsAddressBook,Paint,WindowsSearch,WindowsDis...

 

10Sonic{}

 

WhatIf

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

PSC:\>Move-Itemwindowswindows2-WhatIf

 

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

 

す。

 

Start-Transcript, Stop-Transcript

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

PSC:\>Start-Transcript

 

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

 

04221123.txt

 

PSC:\>Get-Item

 

 

 

ディレクトリ:C:\

 

 

 

ModeLastWriteTimeLengthName

 

 

d----2009/07/1411:37PerfLogs

 

d-r--2012/02/2322:33ProgramFiles

 

d-r--2012/01/1123:31Users

 

d----2012/02/2023:36Windows

 

-a---2009/06/116:4224autoexec.bat

 

-a---2009/06/116:4210config.sys

 

 

 

PSC:\>Stop-Transcript

 

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

 

04221123.txt

 

PSC:\>typeC:\Users\ebi\Documents\PowerShell_transcript.20120304221123.txt

 

 

WindowsPowerShellトランスクリプト開始

 

開始時刻:20120304221123

 

ユーザー名:windows7onMAC\ebi

 

コンピューター:WINDOWS7ONMAC(MicrosoftWindowsNT6.1.7600.0)

 

 

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

 

04221123.txt

 

PSC:\>Get-Item

 

 

 

ディレクトリ:C:\

 

 

 

ModeLastWriteTimeLengthName

 

 

d----2009/07/1411:37PerfLogs

 

d-r--2012/02/2322:33ProgramFiles

 

d-r--2012/01/1123:31Users

 

d----2012/02/2023:36Windows

 

-a---2009/06/116:4224autoexec.bat

 

-a---2009/06/116:4210config.sys

 

 

 

PSC:\>Stop-Transcript

 

 

WindowsPowerShellトランスクリプト終了

 

終了時刻:20120304221138

 

 

PSC:\>

 

Get-WMIObject

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

PSC:\>

 

PSC:\>Get-WmiObject-classWin32_DiskDrive

 

 

 

Partitions:2

 

DeviceID:\PHYSICALDRIVE0

 

Model:VBOXHARDDISKATADevice

 

Size:21467980800

 

Caption:VBOXHARDDISKATADevice

 

.NET Frameworkのクラスの利用

オブジェクト生成

PSC:\>$webclient=New-ObjectSystem.Net.WebClient

 

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

 

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

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

 

hoge

 

アセンブリのロード

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

 

 

GACVersionLocation

 

 

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

 

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

PSC:\>([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ファイルのエクスポート、インポート

PSC:\>Get-Item|Export-Csvc:\tmp\items.csv

 

PSC:\>$items=Import-csvC:\tmp\items.csv

 

PSC:\>$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/1411:37:05

 

CreationTimeUtc:2009/07/142:37:05

 

LastAccessTime:2009/07/1411:37:05

 

LastAccessTimeUtc:2009/07/142:37:05

 

LastWriteTime:2009/07/1411:37:05

 

LastWriteTimeUtc:2009/07/142:37:05

 

Attributes:Directory

 

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

PSC:\>Get-Item|Export-Clixmlc:\tmp\items.xml

 

PSC:\>$items=Import-ClixmlC:\tmp\items.xml

 

PSC:\>$items[0]

 

 

 

ディレクトリ:C:\

 

 

 

ModeLastWriteTimeLengthName

 

 

d----2009/07/1411:37PerfLogs

 

 

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

$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の基本情報を取得する