ウインドウズプロパティcsv書き出し.ps1
ハッシュ値(SHA256)を使う方法
---
グーグルドライブでプロパティが消える理由 - d9bda861230f9223
---
2026-2-2
CSV出力スクリプト修正提案 - c547abdd6f71dde9
PowerShell
# ==========================================
# 対象フォルダ(ここを自分の環境に合わせて書き換えてけろ)
$folderPath = "D:\OneDrive - Business\ドキュメント\2022\研究資料\昔ランタン"
# 出力CSVのパス
$outputCsv = "$folderPath\file_properties_fixed.csv"
# ==========================================
# Shell COM オブジェクト作成
$shell = New-Object -ComObject Shell.Application
$folder = $shell.Namespace($folderPath)
# 取得したい「肝心な項目」とWindows内部インデックスの対応表
# 日本語OSの一般的なインデックス番号だべ
$targetMap = [ordered]@{
"ファイル名" = -1 # 特殊扱い
"タイトル" = 21
"件名" = 22
"タグ" = 24
"評価" = 19
"コメント" = 25
"説明" = 34
"作成日時" = 4
"更新日時" = 3
"サイズ" = 1
"種類" = 2
}
# フォルダ内のファイル一覧を取得して処理
$result = Get-ChildItem -Path $folderPath -File | ForEach-Object {
$file = $_
$item = $folder.ParseName($file.Name)
# 1ファイルごとのデータ格納箱を作成
$objProps = [ordered]@{}
foreach ($entry in $targetMap.GetEnumerator()) {
$label = $entry.Key
$index = $entry.Value
if ($index -eq -1) {
$objProps[$label] = $file.Name
} else {
# Windowsプロパティから値を取得
$val = $folder.GetDetailsOf($item, $index)
# 値が空でも「""(空文字)」を入れて列を固定するんだべ
$objProps[$label] = if ($val) { $val } else { "" }
}
}
# オブジェクトとして出力
[PSCustomObject]$objProps
}
# CSVに出力(Excelで開いても文字化けしないよう UTF8のBOM付きで保存)
$result | Export-Csv -Path $outputCsv -Encoding UTF8 -NoTypeInformation
Write-Host "完了したべ! CSVを確認してみてけろ:$outputCsv"