powershell 将本地文件的属性导出为CSV文件。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 将本地文件的属性导出为CSV文件。相关的知识,希望对你有一定的参考价值。

# ----------------------------------------------
# Author: Romain Blanchard
# Date: 22.03.2013
# Description: Export local file's property to CSV file.
# ----------------------------------------------

# -- Options -- #
$LocalPath = "files"
$logfile = "output-filename.csv"
$count = 0
$begindate = Get-date
$logfileexist = Test-path $logfile

# -- Script -- #
if ($logfileexist -eq "True"){ remove-item -path $logfile -Confirm:$false }
write-output "FileName" | out-file -filepath $logfile -append

try
{
	## Get all items into the folder
	$localFolder = Get-ChildItem $LocalPath
	$count_item = $localFolder.Count
	
	## Foreach items in the folder, export the name 
	$localFolder | ForEach-Object {
		
		## Change 'Name' by the property of your choice
		$filename = $_.Name
		write-output "$filename" | out-file -filepath $logfile -append	
		$count++
		$a = ($count / $count_item)
		$b = "{0:P2}" -f $a
		Write-Progress -activity "Export filename items from '$LocalPath' folder..." -status "Progress: $b"
	}
	Write-Progress "done" "done" -completed
	
	## Display summary informations about eh export job
	$enddate = Get-date
	$datediff = (($enddate - $begindate)).ToString()
	write-host ""
	write-host "$count filename exported in $datediff min." -ForegroundColor Green
	write-host ""
	write-host "----------------------------------"
	write-host ""
	
	## Display availables properties if someone want to export more
	write-host "Properties availables:"
	Get-ChildItem $LocalPath | Get-Member -MemberType Property
}
catch
{ 
	write-host "The script has stopped because there has been an error: "$_ -foregroundcolor Red
}

以上是关于powershell 将本地文件的属性导出为CSV文件。的主要内容,如果未能解决你的问题,请参考以下文章

Powershell:将所有具有“NetworkRuleSet”属性的 Azure 存储帐户列出/导出到 CSV

powershell 将组成员身份导出为CSV

powershell PS SP将列表导出为CSV

powershell 将少于x个项目的列表导出到CSV文件

powershell 功能 - 数据 - UI:将数据网格导出到CSV文件

powershell 此PowerShell脚本是从SCCM DB获取SCEP日志并将其导出为CSV文件