Ask Your Question
1

How can I use Get-ChildItem with several paths, so that it returns all matching files and their paths, but showing only the name of the server?

asked 2023-05-23 08:34:22 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-23 09:03:01 +0000

nofretete gravatar image

You can use the -Path parameter with comma-separated paths to specify multiple paths, and then use the Select-Object cmdlet to only show the server name. Here is an example:

Get-ChildItem -Path "\\server1\c$\temp","\\server2\d$\files" -Recurse |
Select-Object @{Name="Server";Expression={$_.FullName.Split("\")[2]}}, Name, FullName

This will return all files in the specified paths and their subdirectories, along with their full paths. The Select-Object cmdlet uses a calculated property to extract the server name from the path and rename the property as "Server".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-23 08:34:22 +0000

Seen: 25 times

Last updated: May 23 '23