0
1

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でフォルダの容量をしらべて、HTML出力してみた件

Posted at

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/

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?