【问题标题】:User Profile Names and Sizes into CSV File用户配置文件名称和大小到 CSV 文件
【发布时间】:2019-03-24 10:03:13
【问题描述】:

此脚本获取计算机上的用户配置文件,我能够将输出提供到文本文件中,但我不知道如何将此信息导出到 CSV 文件。

dir C:\Users | foreach -Begin {} -Process {
    $size = (dir $_.FullName -Recurse -Force -EA SilentlyContinue | Measure-Object ‘length’ -Sum -Maximum).Sum
    Write-Output ("{0:n2}" -f ($size/1MB) + " MB", $_.FullName) >> "C:\scripts\UserProfiles\UserProfiles.txt"
}

【问题讨论】:

    标签: powershell csv export-csv


    【解决方案1】:

    您需要创建一个具有属性的对象,然后使用Export-Csv

    Get-ChildItem C:\Users |
        ForEach-Object `
            -Begin { Write-Host -Object "Scanning user directories" } `
            -Process {
                Write-Host "Scanning path '$($_.FullName)'"
                $Size = (Get-ChildItem $_.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object ‘length’ -Sum -Maximum).Sum
    
                [pscustomobject] @{
                    Name = $_.Name
                    Path = $_.FullName
                    Size = '{0:N2} MB' -f ( $Size / 1MB )
                }
            } |
            Export-Csv -Path C:\Scripts\UserProfiles\UserProfiles.csv -NoTypeInformation
    

    【讨论】:

      猜你喜欢
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-08
      • 2022-10-24
      相关资源
      最近更新 更多