4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Powershellでのecho、Write-Host、Write-Outputの違い

Posted at

Powershellで下記の3つのコマンドの出力結果の違いを検証しました。

############################################
#   echo、Write-Host、Write-Outputの違い    ###
#  新規作成  2023/3/29                    ###
############################################


Write-Host "***** echo コマンドの出力結果"
echo $PSVersionTable

Write-Host "***** Write-Host コマンドの出力結果"
Write-Host $PSVersionTable


Write-Host "***** Write-Out コマンドにパイプでFormat-Listの出力結果"
Write-Output $PSVersionTable | Format-List

出力結果です
echo コマンドの結果

Name                           Value                                                                                                 
----                           -----                                                                                                 
PSVersion                      5.1.19041.2673                                                                                        
PSEdition                      Desktop                                                                                               
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                               
BuildVersion                   10.0.19041.2673                                                                                       
CLRVersion                     4.0.30319.42000                                                                                       
WSManStackVersion              3.0                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                   
SerializationVersion           1.1.0.1              

Write-Hostでの出力結果

***** Write-Host コマンドの出力結果
System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.Dictionary
Entry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collections.Dict
ionaryEntry

Write-OutputにパイプでFormat-Listを付けたときの結果

Name  : PSVersion
Value : 5.1.19041.2673

Name  : PSEdition
Value : Desktop

Name  : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}

Name  : BuildVersion
Value : 10.0.19041.2673

Name  : CLRVersion
Value : 4.0.30319.42000

Name  : WSManStackVersion
Value : 3.0

Name  : PSRemotingProtocolVersion
Value : 2.3

Name  : SerializationVersion
Value : 1.1.0.1

以上のように違いが出ます。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?