gpt4 book ai didi

powershell - Powershell列表以递归方式将属性存储到CSV

转载 作者:行者123 更新时间:2023-12-03 01:10:11 26 4
gpt4 key购买 nike

我正在尝试使用文件夹中包含的文件的所有属性填充一个csv文件。我在恢复文件版本和程序集时遇到麻烦

$arr = @()
gci C:\Temp -recurse | ? {$_.PSIsContainer -eq $False} | % {
$obj = New-Object PSObject
$obj | Add-Member NoteProperty Directory $_.DirectoryName
$obj | Add-Member NoteProperty Name $_.Name
$obj | Add-Member NoteProperty Size (Get-Item $_.Length/1MB)
$obj | Add-Member NoteProperty Owner ((Get-ACL $_.FullName).Owner)
$obj | Add-Member NoteProperty LastAccess $_.LastAccessTime
$obj | Add-Member NoteProperty Extension $_.Extension
$obj | Add-Member NoteProperty Creation $_.CreationTime
$obj | Add-Member NoteProperty LastWrite $_.LastWriteTime
$obj | Add-Member NoteProperty ReadOnly $_.IsReadOnly
$obj | Add-Member NoteProperty FullName $_.FullName
$obj | Add-Member NoteProperty Date (Get-Date -format "yyyy-MM-d HH:mm")
$obj | Add-Member NoteProperty Version ($_.FileVersion)
$obj | Add-Member NoteProperty Assembly ($_.AssemblyVersion)
$arr += $obj
}
$arr | Export-CSV -notypeinformation "c:\temp\File\report.csv"

最佳答案

1)您所面临的问题是由于许可。尝试以提升模式运行脚本(以管理员身份运行)。
2)您不应尝试将任何内容保存在C:\ temp文件夹下。最好在D:\或E:\中创建一个文件夹,并将其放置为D:\ temp_dump \ report.csv
3)如果您将get-item放在尺寸上,那是无效的,因为您必须选择文件夹内的任何内容。

以下脚本工作正常。

##########################################################

$arr = @()
$Folder_path="E:\PS"

gci $Folder_path | ? {$_.PSIsContainer -eq $False} | % {

$obj = New-Object PSObject

$obj | Add-Member NoteProperty Directory $_.DirectoryName

$obj | Add-Member NoteProperty Name $_.Name

$obj | Add-Member NoteProperty Size (Get-ChildItem $Folder_path | Measure-Object -property length -sum)

$obj | Add-Member NoteProperty Owner ((Get-ACL $_.FullName).Owner)

$obj | Add-Member NoteProperty LastAccess $_.LastAccessTime

$obj | Add-Member NoteProperty Extension $_.Extension

$obj | Add-Member NoteProperty Creation $_.CreationTime

$obj | Add-Member NoteProperty LastWrite $_.LastWriteTime

$obj | Add-Member NoteProperty ReadOnly $_.IsReadOnly

$obj | Add-Member NoteProperty FullName $_.FullName

$obj | Add-Member NoteProperty Date (Get-Date -format "yyyy-MM-d HH:mm")

$obj | Add-Member NoteProperty Version ($_.FileVersion)

$obj | Add-Member NoteProperty Assembly ($_.AssemblyVersion)

$arr += $obj

}

$arr | Export-CSV -notypeinformation "E:\report.csv"

关于powershell - Powershell列表以递归方式将属性存储到CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40613864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com