Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
foreachループがあり、write-hostコマンドレットを使用してコンソールに書き込みます。ここで、ループからのすべての結果を格納する変数に行を書き込みたいと思います。このためのコマンドレット/構文は何ですか?
これを行うには、いくつかの方法があります。行を1つの文字列に入れる:
$lines = '' for ($i=0; $i -lt 10; $i++) { $lines += "The current value of i is $i`n" } $lines
または、各行が配列内の異なる要素である文字列の配列として:
$lines = @() for ($i=0; $i -lt 10; $i++) { $lines += "The current value of i is $i" } $lines