myITforum.com Community Forum myITforum.com Community Forum

Home  Forums  Blogs  Live Support chat  Search Articles  Wiki  FAQ  Email Lists  Register  Login  My Profile  Inbox  Address Book  My Subscription  My Forums 

Photo Gallery  Member List  Search  Calendars  FAQ  Ticket List  Log Out

All Forums RSS Feed Subscription:


  


getting the path when recursively listing directories

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
  Printable Version
All Forums >> [Scripting Technologies] >> Windows PowerShell >> getting the path when recursively listing directories Page: [1]
Login
Message << Older Topic   Newer Topic >>
getting the path when recursively listing directories - 8/13/2008 6:27:05 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
I'm trying to recursively list files/folders that meet a search string criteria that returns their path and owner name, but the path comes back with Microsoft.PowerShell.Core\FileSystem::\\servername\etc\etc and then ends up with 3 elipses (...). In other words, I don't get the "real" path (the short version). AND the owner ends up being their OID rather than something like domain\userid. Here's the one-liner I'm using:
gci -path $path -force -rec | select-string -list -casesensitive -pattern $SearchString | get-acl | ft path,owner -auto > c:\string_search.txt

Post #: 1
RE: getting the path when recursively listing directories - 8/14/2008 10:02:41 PM   
martylist

 

Posts: 41
Score: 0
Joined: 6/10/2005
From: Colorado, USA
Status: offline
Since you're using "select-string" it looks like you're using the V2 tech preview, which I don't have installed at the moment.  This works on PowerShell 1.0: >get-childitem $path -filter $SearchString | get-acl | format-table PsChildName,Owner PSChildName                             Owner
-----------                             -----
Dir1.txt                                BUILTIN\Administrators
Dir2.txt                                BUILTIN\Administrators
Dir3.txt                                BUILTIN\Administrators
reg1.txt                                BUILTIN\Administrators
reg2.txt                                BUILTIN\Administrators
reg3.txt                                BUILTIN\Administrators
Tmp.txt                                 BUILTIN\Administrators
 

(in reply to lcox)
Post #: 2
RE: getting the path when recursively listing directories - 8/15/2008 3:36:51 PM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
On one of my machines I have V2 and the other i do not.
Is it possible to get the directory path (minus the the long Microsoft....:: that comes before it) for each of the files/folders?

(in reply to martylist)
Post #: 3
RE: getting the path when recursively listing directories - 8/27/2008 9:37:16 AM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
Use the directoryname property to get the full folder name or FullName if you want the path and filename

_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to lcox)
Post #: 4
RE: getting the path when recursively listing directories - 8/27/2008 10:16:16 AM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
Thanks! How would the code look again? 

(in reply to SAPIENScripter)
Post #: 5
RE: getting the path when recursively listing directories - 8/27/2008 11:08:03 AM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
Now that I look closer the problem is that by the time you get to needing the filepath, you no longer have the original file object, you have an ACL object which doesn't have the property you need.  There may be a more elegant solution but I simply parsed the PSPath value to get just the filepath.

gci -path $path -force -rec | select-string -list -casesensitive -pattern $SearchString | get-acl | ft @{label="Path";Expression={$_.pspath.substring($_.pspath.indexof("::")+2)}},owner  -auto


_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to lcox)
Post #: 6
RE: getting the path when recursively listing directories - 8/27/2008 11:16:57 AM   
lcox

 

Posts: 82
Score: 0
Joined: 12/10/2003
Status: offline
THAT'S THE TICKET!! I would have never figured this out. I simply incorporated that into my previously built powershell script and it came back just as I had hoped. NOW....I need to decipher what you did!  
Is the key in the @ symbol?

(in reply to SAPIENScripter)
Post #: 7
RE: getting the path when recursively listing directories - 8/27/2008 11:27:13 AM   
SAPIENScripter

 

Posts: 100
Score: 0
Joined: 5/15/2007
From: SAPIEN Technologies
Status: offline
In format-table I'm creating a custom label using a hash table which is what the @ symbol is doing. The hash table (aka associative array) is like a dictionary object.  The first part is the key and the second is the value. In this case a label and then an expression to return a value. The expression is any powerShell code inserted into the {}.

_____________________________

Jeffery Hicks
Microsoft MVP - Windows PowerShell
http://blog.SAPIEN.com
coming soon: Managing Active Directory with Windows PowerShell: TFM
followme: http://www.twitter.com/jeffHicks

(in reply to lcox)
Post #: 8
Page:   [1]
All Forums >> [Scripting Technologies] >> Windows PowerShell >> getting the path when recursively listing directories Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts



  
Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.344