We help IT Professionals succeed at work.

Need help Creating a Powershell script

244 Views
1 Endorsement
Last Modified: 2017-04-17
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

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 CrawfordTransport Ninja
CERTIFIED EXPERT

Commented:
What is in the .txt file?  UNC paths or server names/IPs?  Where are you going to save the keywords?
Chris DentPowerShell Developer
CERTIFIED EXPERT
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.
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
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Senior IT System EngineerSenior Systems Engineer
CERTIFIED EXPERT

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