Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: File search – multiple remote servers – specific file types?

$
0
0

Jake:

I’ve written a one-liner as an example. It gets the computer names from a text file, then gets the files with the desired extensions on the system drive on each computer, gets the properties you need and exports it to a csv.
I’m a beginner in PowerShell too, so I’m sure my example isn’t the shortest and smartest, but it does what you described. Invoke-Command puts a few extra columns into the csv file, but everything you need is there too.


Invoke-Command -ComputerName (Get-Content C:\computers.txt) -ScriptBlock {dir c:\ -Recurse -File |
where {$_.Extension -eq ".txt" -or $_.Extension -eq ".ps1" -or $_.Extension -eq ".docx"} |
select Length,LastAccessTime,Name,@{n='Path';e={$_.fullname}},@{n='Owner';e={$_.getaccesscontrol().owner}}} |
Export-Csv C:\files.csv -NoTypeInformation

Dave:

If I use $env:SystemDrive instead of just c:\, the command generates no output at all. Do you know why?
If this push method isn’t very reliable, isn’t it possible to use the custom script DSC resource (sorry, I don’t know its exact name) and a pull server?
Then, the servers would pull the script and could append the results onto a csv file in a file share. What about that?


Viewing all articles
Browse latest Browse all 13067

Trending Articles