Link to home
Start Free TrialLog in
Avatar of AXISHK
AXISHK

asked on

Extract a portion in powershell result

Run get-acl d:\dept-home  | Select-Object path, accesstostring

Is it possible to simplify the output to show something like  D:\dept-home    Domain Admin...  ?  Thx

Path                                                                                                               AccessToString                                                                  
----                                                                                                                      --------------                                                                  
Microsoft.PowerShell.Core\FileSystem::D:\dept-home                                MYDOMAIN\Domain Admins Allow  FullControl...                            


Thx
SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AXISHK
AXISHK

ASKER

For the Access field, I want to format the output like john, Mary, etc which require to extract the value inside the string like mydomain\john .... mydomain\mary .

How can I archive this result ?

Thx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AXISHK

ASKER

The below code works fine but I change one line to remove top folder path, it returns with error :

Cannot find an overload for "SubString" and the argument count: "1".
At C:\Scripts\test.ps1:10 char:5
+     $temp.Folder = $_.Fullname.SubString(($_.Fullname.LastIndexOf($path),100))
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest

$temp.Folder = $_.Fullname.SubString(($_.Fullname.LastIndexOf($path),100))




$path = @()
$users = @()
$path = "D:\dept-home"

$details = New-Object System.Collections.ArrayList

get-childitem $path  | foreach {If ($_.psiscontainer)  {
    $temp = "" | select "Folder", "Access" 
    $StrPath = 
    $temp.Folder = $_.Fullname 

    $users = (get-acl $_.FullName).Access |select -expandproperty identityreference |% {$_.value.split('\')[1]}
    $temp.Access = $users
    
    $details.Add($temp) | Out-Null
}}
 write-output $details

Open in new window

Remove
$StrPath = 

Open in new window

no point in it being there since not assigned to anything.

What is the full scope of what you need to achieve?

If you just want ACLs for a named folder the script I put in does that, to export just add this to the bottom.

$details |export-csv -path c:\temp\ACLexport.csv -notypeinformation

Open in new window


Do you want recursive folder ACLs for all sub folders as well?
Avatar of AXISHK

ASKER

Export CSV has been fixed but can't trim the path with the following error :

$temp.Folder = $_.Fullname.SubString(($_.Fullname.LastIndexOf($path),100))

Cannot find an overload for "SubString" and the argument count: "1".
At C:\Scripts\test.ps1:10 char:5
+     $temp.Folder = $_.Fullname.SubString(($_.Fullname.LastIndexOf($path),100))
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodCountCouldNotFindBest
What are you wanting to trim?

At the moment $_.fullname is returning the full path so

d:\dept-home\folder1

If you just want the 'folder1' bit then change fullname, to name, so $_.name, which would return

folder1