kuzum
asked on
powershel for folder sizes
HI
Could you please share a powershell script that looks for a specifc folder from given path such as \\server\sharedfolder1
\\server\\sharedfolder2 and reports me in GB in a excel sheet please.
I do not want to be checking my shares manually and hence powershell would be good idea?
Could you please share a powershell script that looks for a specifc folder from given path such as \\server\sharedfolder1
\\server\\sharedfolder2 and reports me in GB in a excel sheet please.
I do not want to be checking my shares manually and hence powershell would be good idea?
ASKER
im receving error and it is indicating that it can not open the file "D:\myname\dirs.csv
I saved the shared path in excel format?
there is spaces in the shared path which is \\abc-nasfs\foldername
folder name has spaced like Customer Services team where you see the spaces in the " customer services team"
I saved the shared path in excel format?
there is spaces in the shared path which is \\abc-nasfs\foldername
folder name has spaced like Customer Services team where you see the spaces in the " customer services team"
ASKER
hi Dustin,
I think I know what the issue is here if Im not wrong. actual share called Customer SErvices team which is a share and when I do right click on the folder and go to properties, size is shown as 0 bytes, however if I go into the shared folder and highlight all the subfolders than I can see the size of it? IS this something we can reflect on the powershell? all it needs to do is check the subfolders of the given shared name and give me the total size?
thanks for your time
I think I know what the issue is here if Im not wrong. actual share called Customer SErvices team which is a share and when I do right click on the folder and go to properties, size is shown as 0 bytes, however if I go into the shared folder and highlight all the subfolders than I can see the size of it? IS this something we can reflect on the powershell? all it needs to do is check the subfolders of the given shared name and give me the total size?
thanks for your time
How big is the actual size (MB/GB)? I tested here with some shares and I get sizes back. You can try this with 4 decimal places to see if it's pulling MB:
My results:
But if I had 2 decimal places it was truncating them to 0.00
$dirlist=import-csv C:\Users\Administrator\Documents\dirs.csv
$outfile = "C:\Users\Administrator\Documents\dirOut.txt"
echo "Name,Size" >> $outfile
ForEach ($path in $dirlist) {
$name=$path.name
$totalsize = (get-childitem "$name" -recurse -force | measure-object -property length -sum)
$name + "," + "{0:N4}" -f ($totalsize.sum / 1GB) + " GB" >> $outfile
}
My results:
Name,Size
\\localhost\share\Clients,0.0034 GB
\\localhost\share\Company,0.0000 GB
\\localhost\Share,0.0059 GB
But if I had 2 decimal places it was truncating them to 0.00
ASKER
this particular one is 433 GB
ASKER
it says it cannot open file D:\myname\dirs.csv
ASKER
I noticed I Can't use get-content to any of my drives? it is deniying to give me access for some strange resaons? I do have access and I think this is to do with powershell?
thanks
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for your valuable time.
>>>>>>>>>>>For not being able to open the csv, are there any format errors inside the csv? (i.e. is there a comma in any of the paths where the path isn't enclosed in quotes?)>>>>>>>>>
In csv I used d:\shared\sharename . I also used Set-ExecutionPolicy unrestricted too.
strange thing is that I can see anything when I used get-content. this should give me something? yes I am domain admin.
>>>>>>>>>>>For not being able to open the csv, are there any format errors inside the csv? (i.e. is there a comma in any of the paths where the path isn't enclosed in quotes?)>>>>>>>>>
In csv I used d:\shared\sharename . I also used Set-ExecutionPolicy unrestricted too.
strange thing is that I can see anything when I used get-content. this should give me something? yes I am domain admin.
ASKER
I attached the error message.
error.txt
error.txt
Are you running powershell as Admin? (Right click and do PowerShell as Admin)
ASKER
yes and it is still giving me access denied error
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
This will give you an output of the files and their sizes. The example source CSV is attached. Output looks like
Open in new window
dirs.csv