Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Powershell Network Share Info

Hello,

I have a list of network shares that I need to gather info on, I need at least 2 out of 3 of the fields below:

                Capacity Allocated
                Capacity Used
                Capacity Free

I can do the looping through the file with the list of shares etc no problem, just completely unsure how i would gather share info by just the share name i.e \\myserver\share

Any help would be appreciated on that part :)

M
0
mikeyd234
Asked:
mikeyd234
1 Solution
 
Haresh NikumbhCommented:
0
 
mikeyd234Author Commented:
Thanks takecoffe, but that article describes connecting to a server/computer then listing all it's shares, all I have are share names, need to be able to connect via a share name and get it's details.

I was thinking maybe a temp drive map then gather properties on it but seems like a long way around..?
0
 
QlemoC++ DeveloperCommented:
That's a good script there, but can be improved to allow to query more than one server, and allow for some optimizations.
$PC = "server1", "server2"

$Volumes = Get-WMIObject Win32_Volume -ComputerName $PC -ea SilentlyContinue | sort -Descending __Server, {$_.Name.Length}

Get-WMIObject Win32_Share -ComputerName $PC -Filter "Type = 0" | foreach {
  $Share = $_
  $Result = "" | Select Server, Share, Path, Volume, Used, Free, Total
  $Result.Server = $Share.__SERVER
  $Result.Share  = $Share.Name
  $Result.Path   = $Share.Path
  $ShareVolume="" | Select Name 
  Foreach ($Volume in $Volumes | where { $_.__SERVER -eq $Share.__Server } ) 
  { 
    If ( ($Result.Path.Length -ge $Volume.Name.Length) -and ($Volume.Name.Length -gt $ShareVolume.Name.Length) )
    { 
      If ($Result.Path.Substring(0,$Volume.Name.Length) -eq $Volume.Name) { $ShareVolume = $Volume; break } 
    } 
  }
  $Result.Volume = $ShareVolume.Name; 
  [int] $Result.Total  = $ShareVolume.Capacity /1024/1024
  [int] $Result.Free   = $ShareVolume.FreeSpace/1024/1024
  [int] $Result.Used   = ($ShareVolume.Capacity - $ShareVolume.FreeSpace) /1024/1024
  $Result
} | sort Server, Share | ft

Open in new window

0

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now