Avatar of Mike
Mike
Flag for United States of America asked on

Need help Creating a Powershell script

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?..
PowershellVB ScriptScripting LanguagesMicrosoft Server OSWindows OS

Avatar of undefined
Last Comment
Mike

8/22/2022 - Mon
JesterToo

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.
Jason Crawford

What is in the .txt file?  UNC paths or server names/IPs?  Where are you going to save the keywords?
Chris Dent

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Mike

ASKER
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....
Mike

ASKER
Does anybody have any suggestions to the following script post above....
ASKER CERTIFIED SOLUTION
Chris Dent

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Albert Widjaja

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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Mike

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