by Giz059 at 2012-11-21 05:29:59
Hi everybody,by Klaas at 2012-11-21 06:04:26
I’m quite new in the world of Powershell and i’ve been asked to get an information that seems easy to get in powershell but not so when you are in front of your screen
I would like to enumerate all the files contained in all the c:\windows\winsxs subdirectories and for each file i would like to have the number of times it appears
For example : The file "win32k.sys" appears "21" times in all winsxs subdirectories.
Thank’s a lot for the expert advices !
Ghislain
Like this?by selko at 2012-11-21 06:34:04Get-Childitem -Recurse C:\Windows\Winsxs | Group-Object name | Select-Object count, name
Get-ChildItem -Path "C:\Windows\Winsxs" -Recurse | Where-Object { -not $.PSIsContainer } | Group-Object Name | Select-Object Count,Nameby Giz059 at 2012-11-21 06:39:21
with this you only get the filenames without directories
Yes perfect, i just add a date notion to have the file only modify within the past 3 months. It give this :by Giz059 at 2012-11-21 06:40:41
$date= (get-date).AddMonths(-3)
Get-ChildItem . *.sys -Recurse -force | Where-Object {$.LastWriteTime -gt $date} | Group-Object name | Select-Object Count,LastWriteTime,Name,DirectoryName
Get-ChildItem . *.inf -Recurse -force | Where-Object {$.LastWriteTime -gt $date} | Group-Object name | Select-Object Count,LastWriteTime,Name,DirectoryName
Get-ChildItem . *.exe -Recurse -force | Where-Object {$.LastWriteTime -gt $date} | Group-Object name | Select-Object Count,LastWriteTime,Name,DirectoryName
Get-ChildItem . *.dll -Recurse -force | Where-Object {$.LastWriteTime -gt $date} | Group-Object name | Select-Object Count,LastWriteTime,Name,DirectoryName
Can i include all the extension in the same line ? I do this because i don’t want the directories but just the files.
Thank’s a lot
thank’s selko, you give me the answer for the directories before i finish my postby Giz059 at 2012-11-21 06:46:05
sorry, just a small problem, i cannot put both Where-Object {$.LastWriteTime -gt $date} and Where-Object {-not $.PSIsContainer}.by selko at 2012-11-21 06:53:43
It send me an error
you can do this so:by Klaas at 2012-11-21 07:06:35Get-ChildItem . -Include .sys,.inf -Recurse -force | Where-Object {$.LastWriteTime -gt $date -and -not $_.PSIsContainer } | Group-Object name | Select-Object Count,LastWriteTime,Name,DirectoryName
You can’t select Lastwritetime or directoryname after you’ve grouped on name. Selected properties must either be the grouping properties or an aggregation.by Giz059 at 2012-11-22 00:41:31
If the win32k.sys exists 21 times, what do you expect to be in the lastwritetime column? There may be 21 different lastwritetimes.
ok i see. Thank’s Klaas, i will delete the lastwritetime column, it’s no use !