Link to home
Start Free TrialLog in
Avatar of Mike
MikeFlag 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?..
Avatar of JesterToo
JesterToo
Flag of United States of America image

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.
Avatar of Jason Crawford
What is in the .txt file?  UNC paths or server names/IPs?  Where are you going to save the keywords?
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.
Avatar of 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....
Avatar of Mike

ASKER

Does anybody have any suggestions to the following script post above....
ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of Mike

ASKER

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