基本的に私がやろうとしているのは、ネットワーク フォルダーからユーザーのフォルダー サイズを収集し、それを .csv にエクスポートすることです。ディレクトリ構造は次のようになります: network:\Department\user...User's-stuff
私が今持っているスクリプトは、部門のファイル名とユーザーのフォルダー サイズを取得しますが、ユーザー名 (部門内のフォルダー名) は取得しません。TimeStamp については、正しく機能しているかどうかわかりません。次の部門のユーザーで開始するときにタイムスタンプを作成するためのものであるため、基本的に、同じ部門のすべてのユーザーは同じタイムスタンプを持つことになります。
これは私がこれまでに持っているものです:
$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 ファイルでは、ユーザーとタイムスタンプが間違っています。あらゆる/すべての助けに感謝します