![Avatar of Phil Mapfumo](https://filedb.experts-exchange.com/files/public/2021/5/22/56a211e0-8853-483f-a609-d2300e58b71d.png)
Folder sizes using Powershell
Hi
I am trying to get folder sizes of shared folders that are located on network drives. However when l use the Powershell script attached. I only get the first 3 folder sizes within each shared folder that l run the script on. I would like the script to include all the folders in the shared folder. I would appreciate your assistance.
I am trying to get folder sizes of shared folders that are located on network drives. However when l use the Powershell script attached. I only get the first 3 folder sizes within each shared folder that l run the script on. I would like the script to include all the folders in the shared folder. I would appreciate your assistance.
$a = Get-Date
$Year = $a.Year
$Month = $a.Month
$Day = $a.Day
$report = "c:\Scripts\Folder Size $Year$Month$Day.txt"
"Date: " + $a.ToShortDateString() | Out-File -FilePath $report
"Time: " + $a.ToShortTimeString() | Out-File -Append -FilePath $report
Out-File -Append -FilePath $report -InputObject "----------------------------------------------------------------"
Out-File -Append -FilePath $report -InputObject "--- Start of Script ---"
Out-File -Append -FilePath $report -InputObject "----------------------------------------------------------------"
Function RootScan
{
#List all root folders in the drive
$folders = Get-ChildItem -Path $mainfolder | ? { $_.psiscontainer -and $_.FullName -notmatch $exclude}
#$folders = Get-ChildItem -Path $mainfolder -exclude $exclude | ? { $_.psiscontainer -and $_.FullName}
Out-File -Append -FilePath $report -InputObject "Start Root"
ForEach ($folder in $folders)
{
$subFolderItems = (Get-ChildItem $folder.FullName -Recurse | Measure-Object -property length -sum)
$folder.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB" | Out-File -Append -FilePath $report
}
Out-File -Append -FilePath $report -InputObject "Finished Root"
}
Function SubScan
{
#List all Group folders in the GroupDrive
ForEach ($folderGroup in $Group)
{
#Write-Host "This is FolderGroup: $folderGroup"
$foldersGroup = Get-ChildItem -Path $foldergroup | ? { $_.psiscontainer -and $_.FullName}
$SubNum = $SubNum + 1
Out-File -Append -FilePath $report -InputObject "Start $SubNum"
ForEach ($child in $foldersGroup)
{
#Write-Host "This is FoldersGroup: $child"
$subFolderItems = (Get-ChildItem $child.FullName -Recurse | Measure-Object -property length -sum)
$Child.FullName + " -- " + "{0:N2}" -f ($subFolderItems.sum / 1MB) + " MB" | Out-File -Append -FilePath $report
}
Out-File -Append -FilePath $report -InputObject "Finished $SubNum"
}}
$mainfolder = "M:\small"
$SubNum = 2
#Enter Directories Requiring Individual Subfolder Count
#$Group = "C:\Temp\"
#Enter Directories Excluded from Root Count
$exclude = "Users Data", "Test"
RootScan
#SubScan
#$mainfolder = "c:\Temp"
#$SubNum = 1
#Enter Directories Requiring Individual Subfolder Count
#$Group = "c:\Temp"
#Enter Directories Excluded from Root Count
#$exclude = "1"
#RootScan
#SubScan
Out-File -Append -FilePath $report -InputObject "----------------------------------------------------------------"
Out-File -Append -FilePath $report -InputObject "--- End of Script ---"
Out-File -Append -FilePath $report -InputObject "----------------------------------------------------------------"
$a = Get-Date
"Date: " + $a.ToShortDateString() | Out-File -Append -FilePath $report
"Time: " + $a.ToShortTimeString() | Out-File -Append -FilePath $report
#Get-ChildItem | Get-Member -MemberType Property
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
![Avatar of Phil Mapfumo](https://filedb.experts-exchange.com/files/public/2021/5/22/56a211e0-8853-483f-a609-d2300e58b71d.png)
ASKER
Hi Qlemo
You could be right, I have seen the results of one of the drives on the server and it has listed all the folders for the root folder so that means the sctipt is working, so l will re-examine the permissons on the drives that have failed.
You could be right, I have seen the results of one of the drives on the server and it has listed all the folders for the root folder so that means the sctipt is working, so l will re-examine the permissons on the drives that have failed.
![Avatar of Phil Mapfumo](https://filedb.experts-exchange.com/files/public/2021/5/22/56a211e0-8853-483f-a609-d2300e58b71d.png)
ASKER
Hi Qlemo
I have changed the permissions and it has worked, thanks. However l have a new question, l can understand if it is not possible to answer it and l will be happy to close the question. Is it possible to have the script run and scan 3 folders are the same time or am l asking for too much?
I have changed the permissions and it has worked, thanks. However l have a new question, l can understand if it is not possible to answer it and l will be happy to close the question. Is it possible to have the script run and scan 3 folders are the same time or am l asking for too much?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
![Avatar of Qlemo](https://filedb.experts-exchange.com/files/public/2014/8/1/86e70b76-39a8-4083-959b-d622790c5a40.png)
Though, it would be much better to generate objects instead of strings, and export as CSV ...
![Avatar of Phil Mapfumo](https://filedb.experts-exchange.com/files/public/2021/5/22/56a211e0-8853-483f-a609-d2300e58b71d.png)
ASKER
Great thank for your help Qlemo much appreciated!
![Avatar of Phil Mapfumo](https://filedb.experts-exchange.com/files/public/2021/5/22/56a211e0-8853-483f-a609-d2300e58b71d.png)
ASKER
The expert was able to provide an additional solution that was not part of the original question, great guy!
ASKER