Hi,
Can someone tell how to chose a folder amongst 4 folders (4 paths), and chose whichever has the maximum space and then make a folder in that...?
- Edited by MartinWood1 Sunday, July 26, 2015 5:44 PM
Technology Tips and News
Hi,
Can someone tell how to chose a folder amongst 4 folders (4 paths), and chose whichever has the maximum space and then make a folder in that...?
Doesn't change anything. Shares do not have free space. Only volumes, drives and partitions have free space.
Ask you system administratorss to help you sort out how this works. A share and a folder are logicat devices used to group, categorize and share files. They do not have a physical sie and are controlled by th underlying storage system.
Hi Martin,
As jrv said, it doesn't change if you map a share to a drive letter, which makes it look like a drive.
It would still be a share and would report the freespace of the drive its residing on.
To understand it, try this test:
#Copy and paste this in cmd
C: cd\ md C:\Test cd C:\Test md 1,2,3,4 subst Z: C:\Test\1 subst Y: C:\Test\2 subst X: C:\Test\3 subst W: C:\Test\4 subst
Go to My Computer and refresh the screen. Do you see the drives mapped.
#Now in PowerShell, try this again
get-psdrive C,W,X,Y,Z |select name, free
You would notice that its still showing the same values, same as C: Hence if you total and say this much is free in total, that's not true\correct.
To remove:
subst Z: /d
subst Y: /d
subst X: /d
subst W: /d
Hence as jrv said to evaluate the true free space, you need to know the sharepath\drive's actual path or residing drive location.
There is also something called the folder quotas, that you might be intersted in. This is exceptional and if used the scenario and evaluation changes, but all depends on how is the share configured.
The approach you are taking is not the best method to determine free space.(Basically client-side doesn't always get the true-true)
Read the 2nd answer:
This script will select the drive with the most free space and create a new folder:
$drives = 'C', 'E' Get-PSDrive -PSProvider FileSystem | Where Name -in $drives | Sort Free -Descending | Select -First 1 | Foreach { $newfolder = Join-Path -Path $_.Root -ChildPath 'NewFolder' New-Item -ItemType Directory -Path $newfolder -WhatIf }
This script will select the drive with the most free space and create a new folder:
$drives = 'C', 'E' Get-PSDrive -PSProvider FileSystem | Where Name -in $drives | Sort Free -Descending | Select -First 1 | Foreach { $newfolder = Join-Path -Path $_.Root -ChildPath 'NewFolder' New-Item -ItemType Directory -Path $newfolder -WhatIf }
Will not work on shares. Shares do not have free space.
Here is what the fre space on a share lloks like:
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
x FileSystem
\\ws702\scripts
Notice that it is blank.
Works on network drives.
No. It looks like it works if the drive is mapped to the local machine. Look at my last post.
You can also get this information from WMI:
Get-WmiObject -Class Win32_LogicalDisk -Filter 'DriveType=4'