基本上我要做的是从他们的网络文件夹中收集用户文件夹大小,然后将其导出到 .csv,目录结构如下所示:network:\Department\user...User's-stuff
我现在拥有的脚本获取部门文件名和用户的文件夹大小,但不是用户名(部门中的文件夹名)。至于时间戳,我不确定它是否正常工作。它的意思是在下一个部门的用户开始时制作一个时间戳,所以基本上,同一部门的所有用户都将具有相同的时间戳。
这是我到目前为止所拥有的:
$root = "network"
$container= @()
$place = "C:\temp\"
$file = "DirectoryReport.csv"
Function Get-FolderSize
{
BEGIN{$fso = New-Object -comobject Scripting.FileSystemObject}
PROCESS
{
$prevDept = (Split-Path $path -leaf)
$path = $input.fullname
$folder = $fso.GetFolder($path)
$Volume = $prevDept + "-users"
$user = $folder.name #can't figure this part out...
$size = $folder."size(MB)"
if ( (Split-Path $path -leaf) -ne $prevDept)
{
$time = Get-Date -format M/d/yyy" "HH:mm #Probably wrong too..
}
return $current = [PSCustomObject]@{'Path' = $path; 'Users' = $user; 'Size(MB)' = ($size /1MB ); 'Volume' = $Volume; 'TimeStamp' = $time;}
}
}
$container += gci $root -Force -Directory -EA 0 | Get-FolderSize
$container
#Creating the .csv path
$placeCSV = $place + $file
#Checks if the file already exists
if ((test-path ($placeCSV)) -eq $true)
{
$file = "DirectoryReport" + [string](Get-Date -format MM.d.yyy.@h.mm.sstt) + ".csv"
rename-item -path $placeCSV -newname $file
$placeCSV = $place + $file
}
#Exports the CSV file to desired folder
$container | epcsv $placeCSV -NoTypeInformation -NoClobber
但在 CSV 文件中,用户和时间戳是错误的。感谢您的任何/所有帮助