Solved

Powershell Network Share Info

Posted on 2013-06-05
3
273 Views
Last Modified: 2013-11-05
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
Comment
Question by:mikeyd234
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Expert Comment

by:Haresh Nikumbh
ID: 39222633
0
 
LVL 3

Author Comment

by:mikeyd234
ID: 39222814
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
 
LVL 70

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39222871
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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question