Need help Creating a Powershell script

Mike
Mike used Ask the Experts™
on
Greeting Experts,

I need help creating a script that can scan a list of File Shares (from .txt file) on Microsoft Active Directory Infostructure. The script needs to be able to look the name of files ( with difference file extensions)  and folders that contain keywords in the file name. Then put that into a .csv file with the name of the file, path location, date created, and person username who created it.   The purpose of this script it to quickly search for files file names that contain different keywords (i.e. 4-5 keywords) from a text file. Doing this in manual fashion takes too much time, and records can be missed. Where a script can be more efficient processes. Can somebody help me with this task?..
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Could you please provide a step-by-step list of the exact process and does it absolutely have to be a Powershell script?  There may be other simple ways to accomplish what you want.

Commented:
What is in the .txt file?  UNC paths or server names/IPs?  Where are you going to save the keywords?
Chris DentPowerShell Developer
Top Expert 2010

Commented:
The following example supports a very simple keyword list. Including things like file extensions will confuse it.
$keywords = (Get-Content yourList.txt) -join '|'
Get-ChildItem C:\Somewhere -Recurse |
    Where-Object BaseName -match $keywords |
    Select-Object Name, FullName, CreationDate, LastWriteTime,
        @{Name='Owner';Expression={ (Get-Acl $_.FullName).Owner }}

Open in new window

It won't be particularly fast for a large structure, and it only supports that list of 4 or 5 keywords. If you had 20 or more keywords the regular expression it generates ($keywords) would become quite unpleasant.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

MikeSecurity

Author

Commented:
Thanks Chris for the script you posted. I tested the script with keywords ( i.e. names of files on my local drive) and used the direct path to my desktop (Win7) and did not output anything.... any ideas....
MikeSecurity

Author

Commented:
Does anybody have any suggestions to the following script post above....
PowerShell Developer
Top Expert 2010
Commented:
Sorry, lost track.

I can't find any problems with it. This is my test set.
$keywords = ('powershell', 'powershell_ise') -join '|'

# $keywords = (Get-Content yourList.txt) -join '|'
Get-ChildItem C:\Windows -Recurse |
    Where-Object BaseName -match $keywords |
    Select-Object Name, FullName, CreationDate, LastWriteTime,
        @{Name='Owner';Expression={ (Get-Acl $_.FullName).Owner }}

Open in new window

Commented:
Yes it works good on my Windows 10 laptop:

......
Name          : Policy.1.0.Microsoft.Powershell.Security.dll
FullName      : C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Policy.1.0.Microsoft.PowerShell.Security\v4.0_1.0.0.0__31bf3856ad364e35\Policy.1.0.Microsoft.Powershell.Securi
                ty.dll
CreationDate  : 
LastWriteTime : 16/07/2016 9:44:14 PM
Owner         : NT SERVICE\TrustedInstaller

Get-ChildItem : Access to the path 'C:\Windows\ModemLogs' is denied.
At line:4 char:1
+ Get-ChildItem C:\Windows -Recurse |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\ModemLogs:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Get-ChildItem : Access to the path 'C:\Windows\PLA\Reports' is denied.
At line:4 char:1
+ Get-ChildItem C:\Windows -Recurse |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\PLA\Reports:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Get-ChildItem : Access to the path 'C:\Windows\PLA\Rules' is denied.
At line:4 char:1
+ Get-ChildItem C:\Windows -Recurse |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\PLA\Rules:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Get-ChildItem : Access to the path 'C:\Windows\PLA\Templates' is denied.
At line:4 char:1
+ Get-ChildItem C:\Windows -Recurse |
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (C:\Windows\PLA\Templates:String) [Get-ChildItem], UnauthorizedAccessException
    + FullyQualifiedErrorId : DirUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Name          : PowerShellExecutionPolicy.admx
FullName      : C:\Windows\PolicyDefinitions\PowerShellExecutionPolicy.admx
CreationDate  : 
LastWriteTime : 16/07/2016 9:44:14 PM
Owner         : NT SERVICE\TrustedInstaller
.....

Open in new window

MikeSecurity

Author

Commented:
I was able to use this command to and locate the files I needed , thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial