Get shared folder informations on a remote host
Get shared folder informations on a remote host

This script gets the shared folder informations and ACL configured on a remote host (source : http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/1903cfde-ad34-464e-9419-94d07ed9de88/)

Script :

Function Get-NtfsRights($name,$path,$comp){
	$path = [regex]::Escape($path)
	$share = "\\$comp\$name"
	$path = $path -replace "\\ "," "
	$path
	$wmi = gwmi Win32_LogicalFileSecuritySetting -filter "path='$path'" -ComputerName $comp
	$wmi.GetSecurityDescriptor().Descriptor.DACL | where {$_.AccessMask -as [Security.AccessControl.FileSystemRights]} |select `
		@{name="Principal";Expression={"{0}\{1}" -f $_.Trustee.Domain,$_.Trustee.name}},
		@{name="Rights";Expression={[Security.AccessControl.FileSystemRights] $_.AccessMask }},
		@{name="AceFlags";Expression={[Security.AccessControl.AceFlags] $_.AceFlags }},
		@{name="AceType";Expression={[Security.AccessControl.AceType] $_.AceType }},
		@{name="ShareName";Expression={$share}}
}

$computer = "hostname.local.net"

if ($shares = Get-WmiObject Win32_Share -ComputerName $computer | Where {$_.Path}){
	$shares | Foreach { Write-Progress -Status "Get share information on $($_.__Server)" $_.Name
	Get-NtfsRights $_.Name $_.Path $_.__Server}
}
else {"Failed to get share information from {0}." -f $($_.ToUpper())}

<>

My Powershell script categories


Reference
Win32_Share class
The Win32_Share class represents a shared resource on a computer system running Windows. This may be a disk drive, printer, interprocess communication, or other sharable device. For more information about retrieving WMI classes, see Retrieving a Class.
The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties and methods are in alphabetic order, not MOF order.

Syntax

[Provider("CIMWin32")]class Win32_Share : CIM_LogicalElement
{
  uint32   AccessMask;
  boolean  AllowMaximum;
  string   Caption;
  string   Description;
  datetime InstallDate;
  uint32   MaximumAllowed;
  string   Name;
  string   Path;
  string   Status;
  uint32   Type;
};

 

Win32_LogicalFileSecuritySetting class
The Win32_LogicalFileSecuritySetting WMI class represents security settings for a logical file. You cannot enumerate instances of this class.
Windows Server 2003 and Windows XP: Win32_LogicalFileSecuritySetting can be enumerated.
The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order, not MOF order.

Syntax

class Win32_LogicalFileSecuritySetting : Win32_SecuritySetting
{
  string  Caption;
  uint32  ControlFlags;
  string  Description;
  boolean OwnerPermissions;
  string  Path;
  string  SettingID;
};
Get shared folder informations on a remote host

Leave a Reply

Your email address will not be published.