Powershellでフォルダの容量をしらべてHTMLに出力する必要があるためのコード。
$path = "E:\hoge"
Get-ChildItem $path | ? PSIsContainer | % {
$subFolderItems = (Get-ChildItem $_.FullName -Recurse | where Length | measure Length -sum)
[PSCustomObject]@{
Fullname=$_.Name
MB=[decimal]("{0:N2}" -f ($subFolderItems.sum / 1MB))
}
}
$path = "E:\hoge"
$html = @"
<html>
<head>
<title>Folder Sizes</title>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<h1>Folder Sizes</h1>
<table>
<tr>
<th>Folder Name</th>
<th>Size (MB)</th>
</tr>
"@
Get-ChildItem $path | ? PSIsContainer | % {
$subFolderItems = (Get-ChildItem $_.FullName -Recurse | where Length | measure Length -sum)
$html += "<tr><td>$($_.Name)</td><td>$([decimal]("{0:N2}" -f ($subFolderItems.sum / 1MB)))</td></tr>"
}
$html += @"
</table>
</body>
</html>
"@
$html | Out-File "E:\\\\hoge\\\\output.html"
参考にしたサイト:https://it-study.info/powershell/folder-subfolder-check/