grayjfiii
asked on
Directory Size and File count
I have the following script to locate a file called "user.db". How can I get a file count and directory size when the file is found.
$Computer = $env:computername
$strName = $env:username
$Filname = $Computer + "_" + $strName + ".txt"
Get-ChildItem -Path c:\ -Filter "user.db" -Recurse -ErrorAction SilentlyContinue
foreach-object { $Computer + "," + $Computer +"," + $_.Fullname + "," + $_.Length + "," +$_.LastAccessTime} |Out-File c:\Results\$Filname –width 1024
$Computer = $env:computername
$strName = $env:username
$Filname = $Computer + "_" + $strName + ".txt"
Get-ChildItem -Path c:\ -Filter "user.db" -Recurse -ErrorAction SilentlyContinue
foreach-object { $Computer + "," + $Computer +"," + $_.Fullname + "," + $_.Length + "," +$_.LastAccessTime} |Out-File c:\Results\$Filname –width 1024
ASKER
How can I add this to it to get MB for file size
$colItems = (Get-ChildItem C:\Scripts | Measure-Object -property length -sum)
"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
$colItems = (Get-ChildItem C:\Scripts | Measure-Object -property length -sum)
"{0:N2}" -f ($colItems.sum / 1MB) + " MB"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes MB and GB if possible
ASKER
Thank you for the fast response!
Open in new window