-2

I have a long list of shares that I want to see if I can access them. Is there a powershell commandlet that I could use?

I tried the Test-Path command but I believe that returns TRUE regardless of whether I have permissions to access the folder.

I want a similar command that will return TRUE if I can reach a share AND have permission to access it.

Or return FALSE if I can't reach the share or if I have not got permission to access it.

  • 1
    https://stackoverflow.com/help/how-to-ask This use case is a very common thing, and a quick web search using say this, 'Powershell get drive permission', will give you a long list of tech docs, articles, etc. on how to go about this. As well as lots of PowerShell videos on Youtube to teach you about Powershell end to end. – postanote Apr 08 '20 at 15:42

1 Answers1

0

Test-Path only validates the existence of a thing. the *-ACL cmdlets return permissions on an object (file, folder, registry, etc.) Just look for the read permission and note, as a rule/practice, admins don't grant access rights to a user, they grant access rights to a group. So, as long as you are a member of a defined Account Group, you have access.

<#
Get specifics for a module, cmdlet, or function
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-acl?view=powershell-7
#>

(Get-Command -Name Get-Acl).Parameters
(Get-Command -Name Get-Acl).Parameters.Keys
Get-help -Name Get-Acl -Examples
<#
# Results

Get-Acl C:\Windows
Get-Acl -Path "C:\Windows\k*.log" | Format-List -Property PSPath, Sddl

Get-Acl -Path "C:/Windows/k*.log" -Audit | ForEach-Object { $_.Audit.Count }

Get-Acl -Path "HKLM:\System\CurrentControlSet\Control" | Format-List

Get-Acl -InputObject (Get-StorageSubsystem -Name S087)
#>
Get-help -Name Get-Acl -Full
Get-help -Name Get-Acl -Online

You can also use one of the other modules from the Microsoft powershellgallery.com

Find-MOdule -Name '*acl*' | 
Format-Table -AutoSize
<#
# Results

Version     Name                    Repository Description                                                                                                                                 
-------     ----                    ---------- -----------                                                                                                                                 
1.0.1       ACL-Permissions         PSGallery  A couple of ACL utilities, for repairing corrupt permissions and applying permissions for IIS AppPool identities                            
1.30.1.28   ACLReportTools          PSGallery  Provides Cmdlets for reporting on Share ACLs.                                                                                               
1.7         ACLHelpers              PSGallery  Modules to help work with ACLs (Access Control Rights)                                                                                      
1.0.1.0     ACLCleanup              PSGallery  A set of tools to help you clean your fileshares access control lists                                                                       
0.1.2       ACLTools                PSGallery  Module for managing NTFS Acls on files and folders                                                                                          
...
#>


Find-MOdule -Name '*ntfs*' | 
Format-Table -AutoSize
<#
# Results

Version Name                    Repository Description                                                                                                                                     
------- ----                    ---------- -----------                                                                                                                                     
4.2.6   NTFSSecurity            PSGallery  Windows PowerShell Module for managing file and folder security on NTFS volumes                                                                 
1.4.1   cNtfsAccessControl      PSGallery  The cNtfsAccessControl module contains DSC resources for NTFS access control management.                                                        
1.0     NTFSPermissionMigration PSGallery  This module is used as a wrapper to the popular icacls utility to save permissions to a file and then restore those permissions to a mirror c...
#>

(Get-ChildItem -Path D:\temp | Get-NtfsAccess) -Match 'ReadAndExecute'
postanote
  • 15,138
  • 2
  • 14
  • 25