株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

Linuxでいうwhile read line的な感じで。
知ってると結構活躍してくれる(^^)

 

ファイルを読み込むパターン

PS C:\Users\yuta\Desktop> Get-Content .\test.txt
a
b
c
d
e
PS C:\Users\yuta\Desktop> Get-Content .\test.txt | ForEach-Object {Write-Host $_}
a
b
c
d
e
PS C:\Users\yuta\Desktop>

 

変数を読み込むパターン

PS C:\Users\yuta\Desktop> $array = @('a','b','c','d','e')
PS C:\Users\yuta\Desktop> $array | ForEach-Object {Write-Host $_}
a
b
c
d
e
PS C:\Users\yuta\Desktop>

 

エイリアス張られてるからforeachでもOK

PS C:\Users\yuta\Desktop> Get-Alias -name foreach

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           foreach -> ForEach-Object


PS C:\Users\yuta\Desktop>

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)