In a Windows Server & Active Directory environment, where a particular network-share is shared with only certain AD users/groups. Is there a way, using PowerShell, to find out who has read permissions to this share? I tried to follow the instructions on this post, but receive an error, which is shown below after the code sample.
Here is the sample .ps1 code I used to try this:
$cred = Get-Credential -Credential mydomain\myself
$share = "MyTarget"
$cn = "FooBar"
$query = "Associators of {win32_LogicalShareSecuritySetting='$share'}
Where resultclass = win32_sid"
Get-WmiObject -query $query -cn $cn -cred $cred |
Select-Object -Property @{LABEL="User";EXPRESSION=
{"{0}\{1}" -f $_.ReferencedDomainName, $_.AccountName}}, SID
Here is the error message:
Get-WmiObject : Not found
At line:8 char:1
+ Get-WmiObject -query $query -cn $cn -cred $cred |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], ManagementException
+ FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
UPDATE: Per the comment below, I have found that the share I'm looking for is a sub-folder of an actual named share, 2 levels down. Using this line of PowerShell to find that server's named shares:
Get-WmiObject -ComputerName "FooBar" -Class win32_LogicalShareSecuritySetting | select PATH
So for example:
Computer name is FooBar
. One of the many listed shares is MainShare
. Under that folder, we go \SomeStuff\MyTarget
, and MyTarget is the folder I need to look at permissions for. So the full path would be \\FooBar\MainShare\SomeStuff\MyTarget
.
Get-WmiObject -ComputerName <computername> -Class win32_LogicalShareSecuritySetting | select PATH
do you get a list of the share names back?