powershell(その4)
- メソッドやプロパティなどの調べ方
Get-Member を使うとよさげ
-
- 使用例
Get-Host
PS C:\> Get-Host Name : ConsoleHost Version : 5.0.10514.6 (略) CurrentCulture : ja-JP CurrentUICulture : ja-JP PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy DebuggerEnabled : True IsRunspacePushed : False Runspace : System.Management.Automation.Runspaces.LocalRunspace
Get-Hostってどんなメソッドやプロパティが使えるの?
PS C:\> Get-Host | Get-Member TypeName: System.Management.Automation.Internal.Host.InternalHost Name MemberType Definition ---- ---------- ---------- EnterNestedPrompt Method void EnterNestedPrompt() Equals Method bool Equals(System.Object obj) ExitNestedPrompt Method void ExitNestedPrompt() GetHashCode Method int GetHashCode() GetType Method type GetType() NotifyBeginApplication Method void NotifyBeginApplication() NotifyEndApplication Method void NotifyEndApplication() PopRunspace Method void PopRunspace(), void IHostSupportsInte... PushRunspace Method void PushRunspace(runspace runspace), void... SetShouldExit Method void SetShouldExit(int exitCode) ToString Method string ToString() CurrentCulture Property cultureinfo CurrentCulture {get;} CurrentUICulture Property cultureinfo CurrentUICulture {get;} DebuggerEnabled Property bool DebuggerEnabled {get;set;} InstanceId Property guid InstanceId {get;} IsRunspacePushed Property bool IsRunspacePushed {get;} Name Property string Name {get;} PrivateData Property psobject PrivateData {get;} Runspace Property runspace Runspace {get;} UI Property System.Management.Automation.Host.PSHostUs... Version Property version Version {get;}
見つけたメソッド(Method)やプロパティ(Property)を使ってみる
PS C:\> (Get-Host).Version Major Minor Build Revision ----- ----- ----- -------- 5 0 10514 6
PS C:\> (Get-Host).Version.Major 5
PS C:\> (Get-Host).ToString() System.Management.Automation.Internal.Host.InternalHost