What do you mean “This is not working”? When I try that it works just as expected.
You may have misundertood something. The paramter -Name is a switch parameter telling Get-ChildItem to return only the names of the found items - not the default porperty set.
The output would not be the same but at least you should get 2 different lists.
It took me a moment to reproduce the behaviour but I think I got it. It seems that Get-ChildItem ignores the parameter -Recurse when you provide the parameter -Name.
Try the command in a folder where you have files fitting your filter criteria to verify.
You might have found a bug.
To circumvent the bug you may simply use
Get-ChildItem -Filter *to* -Recurse | Select-Object -Property Name
The Get-ChildItem cmdlet uses the Path parameter to specify the directory C:\Test. The Name parameter returns only the file or directory names from the specified path. The names returned are relative to the value of the Path parameter.
Name will back only names, to fix is that add path in command, but we have to be aware of what we get back. When name is used we don’t get any more System.IO.FileInfo object.
Adam is correct. See the help file for the -Name parameter on Get-ChildItem:
PS> Get-Help -Name Get-ChildItem -Parameter Name
-Name <System.Management.Automation.SwitchParameter>
Gets only the names of the items in the location. The
output is a string object that can be sent down the
pipeline to other commands. The names returned are
relative to the value of the Path parameter.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
Alternatively, the -Filter parameter is likely what you are looking for.
For example, to search for FILES AND FOLDERS matching “foo” from the root directory, regardless of current working directory, run the following: Get-ChildItem -Path \ -Filter "*foo*"
Also, you will need to add the -Force parameter to show hidden files.