0
2

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] CSVに列追加、同じ値(文字列 / 日付)を入れる

Last updated at Posted at 2022-01-26

PowerShellを用いて、CSVにカラム(列)を追加し、その全てに同じ値(文字列・日付)を入れる必要がありました。
CSVファイルを$dataに Import-Csv したとしましょう。

##文字列

$newdata = $data | Select-Object *, @{ Name = '列名' ; Expression = {'文字列'} }

結果↓

> $newdata

id name   列名
-- ----   ----
1  taro   文字列
2  hanako 文字列
3  jiro   文字列

##日付

$newdata = $data | Select-Object *, @{ Name = '列名' ; Expression = {(Get-Date).ToString('yyyy/MM/dd')} }

結果↓

> $newdata

id name   列名
-- ----   ----
1  taro   2022/01/26
2  hanako 2022/01/26
3  jiro   2022/01/26

以上。

0
2
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
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?