How to chose a directory amongst 4 directories with the lowest space available and make folder in it.

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...?


July 26th, 2015 5:17pm

OK! so I checked my facts and found out that there are 4 shares -  SHARE1, SHARE2, SHARE3, SHARE4
All have around 1TB of space and around 200GB of free spaces in all ( more or less)

now, I want to compare these freespaces, and whichever has the largest freespace, I want to make a folder in that SHARE....

Now, lets be realistic, is it possible, and if possible - HOW?
Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 11:39am

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.

July 28th, 2015 12:31pm

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:

FSRM Auto Quotas & Display of Volume Used/Free Space:

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 4:25am

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
    }


July 30th, 2015 4:58am

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.

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 5:46am

Works on network drives.
July 30th, 2015 5:58am

Works on network drives.

No.  It looks like it works if the drive is mapped to the local machine.  Look at my last post.

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 6:03am

Works for me if I map the network drive using net use or GPP. Does not work if I map using New-PSDrive. I am not mapping to local machine and have tried with multiple servers.
July 30th, 2015 4:21pm

You can also get this information from WMI:

Get-WmiObject -Class Win32_LogicalDisk -Filter 'DriveType=4'

Free Windows Admin Tool Kit Click here and download it now
July 30th, 2015 6:05pm

If all hares are on the same drive you will get all the same answers.  If they are on DFSR you will get nonsense for numbers.  If quotas are in force you will get nothing of value.
July 30th, 2015 6:31pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics