Solved

Powershell Network Share Info

Posted on 2013-06-05
3
241 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
3 Comments
 
LVL 21

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 68

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now