String Manipulation

This topic contains 2 replies, has 2 voices, and was last updated by  Suresh krishnan 2 years, 1 month ago.

  • Author
    Posts
  • #30940

    Suresh krishnan
    Participant

    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 🙂 . 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 
    
  • #30941

    Curtis Smith
    Participant

    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
    
  • #30942

    Suresh krishnan
    Participant

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

You must be logged in to reply to this topic.