0
votes

I am limited to PowerShell 2.

I am trying to capture all share folders where full control is set for the "everyone" user group.

I have found the PowerShell command below which lists out the current shares, however, it does not list the people it is shared to:

Get-WmiObject -Class Win32_LogicalShareSecuritySetting 

With this check, I would like to make sure no share folders have the "everyone" user group selected to full control.

Can anyone help me with this please?

Edit: To only output the shares if the full control option is present for the everyone user group: enter image description here

1
Get-ACL is the command for checking permissions on a folder/share. You should be able to pass the shares outputted from the WMI class to this command to check permissions. docs.microsoft.com/en-us/powershell/module/…Jonathan Waring
Thank you Jonathan for the feedback, I have tried to add the Get-ACL command to the existing command but it has not worked well and provides no output, any chance you could help?Help
Get-WmiObject win32_logicalsharesecuritysetting | ForEach-Object {$Path = "\\localhost\" + $_.Name; Get-Acl -Path $Path | Select-Object -ExpandProperty Access | Where-Object IdentityReference -eq 'Everyone'} I ran this on my local machine that only has one share but it should work for multiple. If you are running the code on the machine that hosts the shares then it should work as is. If you are running it against a remote machine you can replace \\localhost\ with \\<machinename>\Jonathan Waring
Hi Jonathan, thank you very much, I have tested this on PowerShell 2 and it seems to not output anything, do you know if the above is compatible with older PS versions? Running it on PowerShell 5 seems fine, but I can see that the folder Name/Path is not included, would it be possible to select/display the path in that query output?Help

1 Answers

3
votes

@JonathanWaring is on the right track. The comparison statement in the Where-Object command did not exist till PowerShell 3.0, so we have to adjust the code a little in order it to work with PowerShell 2.0. We should also make it output more information on the path:

$Found = @()

Get-WmiObject win32_logicalsharesecuritysetting | ForEach-Object {
    $Path = "\\localhost\" + $_.Name
    
    Get-Acl -Path $Path | Select-Object Path -ExpandProperty Access | ForEach-Object {
        If($_.IdentityReference -eq 'Everyone' -and $_.FileSystemRights -eq 'FullControl')
        {
            $Found += $_.Path
        }
    }
}

Write-Host "Found: $($Found.Count)"
Write-Host "Share locations:"
$Found | ForEach-Object {
    Write-Host $_.Replace('Microsoft.PowerShell.Core\FileSystem::\\localhost\','')
}