Minggu, 13 Februari 2011

Powershell - List Shares

Our datacenter had some power issues and I needed to quickly determine if our SAN had come back online. The quickest way I could come up with was a gwmi call to the remote machine. My first effort was on the Win32_LogicalDisk class:
gwmi -class Win32_LogicalDisk -computer 192.168.0.14 | select deviceid,drivetype,status,mediatype,access,volumename | ft -auto
If you are not familiar with this class, check out the definition at MSDN:
http://msdn.microsoft.com/en-us/library/aa394173(v=vs.85).aspx
To get a better idea, as this didn't actually list shares but rather all drives, I used the Win32_Share class:
gwmi -class win32_share -computer 192.168.0.14 | select name,status
For more information on this class check out this page:
http://msdn.microsoft.com/en-us/library/aa394435(v=VS.85).aspx
Interestingly enough, I did a Get-Member to be sure I was picking all the info I needed. Since we are in a clustered environment, there is actually a Win32_ClusterShare class that derives from the Win32_Share class. If you run this command:
gwmi -class win32_share -computer 192.168.0.14 | select *
you can see all of the main fields
__GENUS
__CLASS
__SUPERCLASS
__DYNASTY
__RELPATH
__PROPERTY_COUNT
__DERIVATION
__SERVER
__NAMESPACE
__PATH
AccessMask
AllowMaximum
Caption
Description
InstallDate
MaximumAllowed
Name
Path
ServerName
Status
Type
Scope
Options
ClassPath
Properties
SystemProperties
Qualifiers
Site
Container
About the Win32_ClusterShare class:
http://support.microsoft.com/kb/971403
As noted by Radjin Sardjoe Missier in the Win32_Share community content section,
Suppose I have a server named SERVER01 that has a share named SHARE01.

To get this share object in powershell use the command:

[wmi]file://server01/root/cimv2:Win32_Share.Name='SHARE01'

This will also work for a Windows 2003 cluster where SERVER01 is the network name for a cluster group.

However, for a Windows 2008 cluster using CAP this will NOT work, because the Name property is now the UNC path to the share.

In such cases use:

[wmi]file://server01/root/cimv2:Win32_Share.Name='//SERVER01/SHARE01'

Actually for a cluster server the class name is Win32_ClusterShare which is a subclass of Win32_Share.

0 komentar:

Posting Komentar

 
Powered by Blogger