「$host.ui」に関する考察

概要

ホストのIN/OUTに関するインターフェース。

型:System.Management.Automation.Internal.Host.InternalHostUserInterface

確認方法
PS C:\> $host.ui.GetType().FullName
System.Management.Automation.Internal.Host.InternalHostUserInterface

主要メソッド

  • PromptForChoice
  • ReadLine
  • ReadLineAsSecureString
  • Write
  • WriteDebugLine
  • WriteErrorLine
  • WriteLine
  • WriteProgress
  • WriteVerboseLine
  • WriteWarningLine

継承/実装元の型:System.Management.Automation.Host.PSHostUserInterface

確認方法
PS C:\> $host.ui.GetType().BaseType.FullName
System.Management.Automation.Host.PSHostUserInterface

継承階層

確認方法
PS C:\> $host.ui.PSObject.TypeNames
System.Management.Automation.Internal.Host.InternalHostUserInterface
System.Management.Automation.Host.PSHostUserInterface
System.Object

サンプル

様々なWriteメソッド
PS C:\> $host.ui.WriteDebugLine("PowerShell Memo")
デバッグ: PowerShell Memo
PS C:\> $host.ui.WriteVerboseLine("PowerShell Memo")
詳細: PowerShell Memo
PS C:\> $host.ui.WriteWarningLine("PowerShell Memo")
警告: PowerShell Memo
PS C:\> $host.ui.WriteErrorLine("PowerShell Memo")
PowerShell Memo

上記メソッドは以下のコマンドレットと同様の挙動になります。

  • Write-Debug
  • Write-Verbose
  • Write-Warning
  • Write-Error