2023-12-19 00:06:14 +03:00
|
|
|
function Get-Files {
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory)][string]$Path
|
|
|
|
|
)
|
|
|
|
|
$files = Get-ChildItem $Path
|
|
|
|
|
$Collection_Files = New-Object System.Collections.Generic.List[System.Object]
|
|
|
|
|
foreach ($file in $files) {
|
|
|
|
|
if ($file.Length -eq 1) {
|
2023-12-19 12:23:48 +03:00
|
|
|
$type = "Directory"
|
|
|
|
|
$ChildItem = Get-ChildItem -Path $file.FullName -Recurse -ErrorAction Ignore
|
|
|
|
|
$size = ($ChildItem | Measure-Object -Property Length -Sum).Sum/1gb
|
|
|
|
|
$size = [string]([double]::Round($size, 3))+" GB"
|
|
|
|
|
$Files_Count = $ChildItem | Where-Object { $_.PSIsContainer -eq $false }
|
|
|
|
|
$Directory_Count = $ChildItem | Where-Object { $_.PSIsContainer -eq $true }
|
2023-12-19 00:06:14 +03:00
|
|
|
} else {
|
2023-12-19 12:23:48 +03:00
|
|
|
$type = "File"
|
|
|
|
|
$size = $file.Length / 1gb
|
|
|
|
|
$size = [string]([double]::Round($size, 3))+" GB"
|
2023-12-19 00:06:14 +03:00
|
|
|
}
|
|
|
|
|
$Collection_Files.Add([PSCustomObject]@{
|
|
|
|
|
Name = $file.Name
|
|
|
|
|
FullName = $file.FullName
|
|
|
|
|
Type = $type
|
|
|
|
|
Size = $size
|
2023-12-19 12:23:48 +03:00
|
|
|
Files = $Files_Count.Count
|
|
|
|
|
Directory = $Directory_Count.Count
|
2023-12-19 00:06:14 +03:00
|
|
|
CreationTime = Get-Date -Date $file.CreationTime -Format "dd/MM/yyyy hh:mm:ss"
|
|
|
|
|
LastAccessTime = Get-Date -Date $file.LastAccessTime -Format "dd/MM/yyyy hh:mm:ss"
|
|
|
|
|
LastWriteTime = Get-Date -Date $file.LastWriteTime -Format "dd/MM/yyyy hh:mm:ss"
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
$Collection_Files
|
|
|
|
|
}
|
2023-12-19 12:23:48 +03:00
|
|
|
|
2023-12-19 00:06:14 +03:00
|
|
|
# Get-Files -Path "C:/"
|
2023-12-19 12:23:48 +03:00
|
|
|
# Get-Files -Path "C:/Program Files/"
|
|
|
|
|
# Get-Files -Path "D:/"
|
|
|
|
|
# Get-Files -Path "D:/Movies/"
|