0

I am Googling scripts to find a PS script to count file types and files in several directory's on our network.

I have several directory's on my "Libraries" directory on my PC at work.

I'm just trying to test a PS script to get this to work to count the files and list the file types in my "Libraries\Documents\Tidbits" folder:

Get-ChildItem \\hilltop3\users$\LongRandy\My Documents\TIDBITS

but I get this error:

Get-ChildItem : Cannot find path '\\hilltop3\users$\LongRandy\My' because it does not exist.
At line:1 char:14
+ Get-ChildItem <<<< \\hilltop3\users$\LongRandy\My Documents\TIDBITS
+ CategoryInfo : ObjectNotFound: (\\hilltop3\users$\LongRandy\My:String) [Get-ChildItem], ItemNotFoundExc
eption
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand"

Thanks again

4 Answers 4

0

Try this:

$files = Get-ChildItem "\\hilltop3\users$\LongRandy\My Documents\TIDBITS" -recurse | where{$_.mode -notlike "d*"}
$files | group-object -Property extension | sort count -Descending
2
  • It worked, many thanks. But, why do you have the "$files =" at the beginning of the line?
    – DATAfiend
    Commented Mar 25, 2015 at 18:23
  • That stores the result of the Get-Childitem in a variable. All variables in Powershell begin with $ sign. Storing a result of a long query in a variable allows you to filter, group, etc it without having to wait for Get-Childitem to return all of the files.
    – megamorf
    Commented Mar 25, 2015 at 22:17
2

Because your file path has a space in it, you need to wrap it in quotes so that PowerShell knows it's a single string/argument.

Notice in the error:

Cannot find path '\hilltop3\users$\LongRandy\My' because it does not exist.

It stops at the Space after My because spaces are used to distinguish between individual arguments in the command.

Try something like:

Get-ChildItem "\\hilltop3\users$\LongRandy\My Documents\TIDBITS"

0

You can try this:

Get-Childitem X:\ -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc

Where

X:\ = "\hilltop3\users$\LongRandy\My Documents\TIDBITS"

So:

Get-Childitem "\hilltop3\users$\LongRandy\My Documents\TIDBITS" -Recurse | where { -not $_.PSIsContainer } | group Extension -NoElement | sort count -desc

Should work.

0

How did you get that path? Are you sure that it is really \\hilltop3\users$\LongRandy\My Documents\TIDBITS? It looks like a directory that might have been setup by folder redirection. Which means it might have a hidden desktop.ini file that gives the folder a different name in the Windows GUI from what you would use at the command line. The default documents folder redirection path is named 'Documents', not 'My Documents'.

For example on my network most users have a path that might look like \\example.org\dfs\do\username\My Documents, but the real path is \\example.org\dfs\do\username\Documents. Windows adds a desktop.ini file in the folder that looks like this.

[ExtShellFolderViews]
...
Owner=username
Personalized=5
PersonalizedName=My Documents
...

Past that, as others mentioned, you Probably just need to quote your path.

1
  • zoredache, It looks like megamorf's script worked. I'm still curious about the default name for "My Documents". Is this common to change My Documents to Documents or vice versa?
    – DATAfiend
    Commented Mar 25, 2015 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .