String Manipulation

Dear Community
I need help with my script. I wrote a small script to retrive acl information about network share drive. I wanted to output this result to a text file using the same share drive name .

Example :- if my network share drive is \server.example.db.com\test\myshare

Then i want the output file name like myshare.txt

I have tried some stirng manuplation techniques like trim,replace but i could not get the results what i am looking for .
Or
If there is any other way this can be achieved i am glad to hear that as well :slight_smile: . Thanks.

$share = Read-Host " Enter full share drive path"

$acl = Get-Acl -Path $share

Write-Host "Retriving ACL List for the share"

$acl.Access | select IdentityReference,FileSystemRights | Format-Table -AutoSize | out-file result.txt 

You can use split-path to get the “leaf” of the path.

$share = Read-Host " Enter full share drive path"
$outfile = "$(Split-Path $share -Leaf).txt"

$acl = Get-Acl -Path $share

Write-Host "Retriving ACL List for the share"

$acl.Access | select IdentityReference,FileSystemRights | Format-Table -AutoSize | out-file $outfile

Thank you so much Curtis for taking your valuable time to reply . It worked :slight_smile: . Thanks again …