Solved

get acl and dir commands

Posted on 2014-02-12
6
391 Views
Last Modified: 2014-02-18
is there an easy way to possibly combine a DIR command and the powershell get-acl command to get a list of acl's for all folders (folders only, no files, or sub directories) in a share.

i.e.\\server\share\dir1 \\server\share\dir2 \\server\share\dir3

or any other way to acheive this within powershell?
0
Comment
Question by:pma111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 70

Accepted Solution

by:
Qlemo earned 250 total points
ID: 39852672
Something like this?
dir C:\temp\ee,c:\temp  | ? { $_.PsIsContainer } | get-acl 

Open in new window

0
 
LVL 3

Author Comment

by:pma111
ID: 39852683
new to powershell, but can you explain what the -psiscontainer switch does, I need the command to automatically list only root level directories, as opposed to hard code them.
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 39852822
PsIsContainer isn't a switch, it is a property of filesystem objects. If set, the object is a folder, else it is a file.

To explain above line, I'll have to dissect it:
dir a,b,c,d:    you need to use the comma here, because that makes an array, and you need to provide a string array if you want to stuff in more than one folder/file name.  dir a b will use the default position resolution for the get-childitem cmdlet (which dir is an alias for), assigning "a" to the first (= path), and "b" to the second (= filter expression = wildcards).

| ? { $_.PsIsContainer }   filter to get only folders. ? is where-object, and $_ is "the current object of a pipeline" (you can see that in a lot of commands).

The result is then just pushed into get-acl, which knows about how to handle filesystem objects. It could also handle path names as plain string if needed, but passing thru the filesystem object is much more straight-forward if available.
0
 
LVL 3

Assisted Solution

by:Tommy_Cooper
Tommy_Cooper earned 250 total points
ID: 39852865
New to Powershell?  The biggest thing to remember is that when powershell returns things to you, it is NOT returning just the text you see but it returns entire objects.

To see what it is returning use the Get-Member cmdlet.  Example - create C:\Temp
Then run:
Get-ChildItem c:\temp| Get-Member

Open in new window

So you're running the Get-ChildItem command and it returns a powershelll object.  Then you're piping that object to Get-Member that will show you all the properties (well, members really. Because it will also contain things like methods and other stuff) that the object contains.  

As Qelmo said, when you do $_ you are selecting the current object that has been returned and when you add .PsIsContainer you're selecting just that property of the current object.

Does that make sense?
0
 
LVL 3

Author Comment

by:pma111
ID: 39852876
makes sense, thanks both..
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question