我正在尝试使用PowerShell列出我的Windows系统上的每个文件,包括dll,exe,驱动程序列表等。
以下列出了仅名为“Users”
的特定文件夹的列表Get-ChildItem C:\Users -Recurse | Select-Object DirectoryName,Name |Where { $_.DirectoryName -ne $NULL } | Export-CSV C:\Filelist.csv
它仅显示“用户”文件夹中的文件列表,当我尝试按照我的目标使用以下命令列出C
驱动器下的所有文件时出现错误:
Get-ChildItem C:\ -Recurse | Select-Object DirectoryName,Name | Where { $_.DirectoryName -ne $NULL } | Export-CSV C:\Filelist.csv
我收到此错误:
ERROR : Get-ChildItem : Access to the path ‘C:\Windows\CSC\v2.0.6’ is denied.
At line:1 char:14
+ Get-Childitem <<<< C:\ -Recurse | Select-Object DirectoryName,Name | Where { $_.DirectoryName -ne $NULL } | Export-CSV C:\Filelist.csv
+ CategoryInfo : PermissionDenied: (C:\Windows\CSC\v2.0.6:String) [Get-ChildItem], UnauthorizedAccessException
+ FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
如何在系统中列出整个 C
驱动器或所有文件(包括dll,脚本,exe文件)并导出到CSV文件?
答案 0 :(得分:0)
您必须以 admin 的身份执行脚本。此外,您可以省略错误消息,查找您无法使用-ErrorAction
常用参数访问的文件:
Get-ChildItem C:\ -Recurse -ErrorAction SilentlyContinue |
Select-Object DirectoryName,Name |
Where { $_.DirectoryName -ne $NULL } |
Export-CSV C:\Filelist.csv