How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (2024)

How to Find a File and Check If It Exists with Powershell or Netwrix Auditor

Native Auditing vs. Netwrix Auditor for Windows File Servers

Native Auditing Netwrix Auditor for Windows File Servers

  1. Open the PowerShell ISE.
  2. Run a script like the following, which will return all files in the Accounting folder whose filename includes the string “payroll”:

$filename = '*payroll*.*'#you can use wildcards here for name and extension
$searchinfolder = '\\pdc\Shared\Accounting*'
Get-ChildItem -Path $searchinfolder -Filter $filename -Recurse | %{$_.FullName}

The results will show all matching files.

How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (2)

Once you have a list of files that might contain sensitive data, you might want to move them to a secure location. However, your processing script will terminate with an error if the file path is invalid, so before running it, you should first check for the existence of the file or folder. The following PowerShell commands will help:

  • Using Get-Item tocheck if a file exists — You can use the Get-Item cmdlet in PowerShell to find a file by name. If the specified item path does not exist, the script will throw an error. Below is a PowerShell script that checks whether the file "Payroll 2022 - 2023.xlsx" exists using the Get-Item cmdlet. If the file exists, the script provides the file details; if not, it will display a message saying the file does not exist.

$file="C:\Shared\Accounting\Payroll 2022 - 2023.xlsx"

if (Test-Path$file) {

$item=Get-Item$file

Write-Host"The file exists. Details:"

$item

}else {

Write-Host"The file does not exist."

}

How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (3)
  • Using Get-ChildItem to check if a file exists —The Get-ChildItem cmdlet is typically used to retrieve a list of items in a specified location, but it can also be used to check for the existence of a specific file. The script below attempts to retrieve the file "Payment_2021.rtf". If the file exists, the script will return the file details and a success message; otherwise, no output will be returned by Get-ChildItem and the write host cmdlet will display the message "The file does not exist."

$file="C:\Shared\Accounting\payment_2021.rtf"

$items=Get-ChildItem$file

if ($items) {

Write-Host"The file exists."

}else {

Write-Host"The file does not exist."

}

How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (4)
  • Using Test-Path to check if a file exists —You can use the Test-Path cmdlet to check whether a specific file or folder exists. It returns True if the file or folder exists and False if it does not. For example, to check whether the “Payroll 2022 – 2023” file exists, run the following script:

Test-Path-Path'C:\Shared\Accounting\Payroll 2022 - 2023.xlsx'

To determine whether there are any files in C:\Shared\Accounting\ that have the .xlsx extension, run following Test-Pathcmdlet:

Test-Path-Path"C:\Shared\Accounting\*"-Include*.xlsx

How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (5)

You can also use Test-Path to check whether a path is a file or a directory. Add the ‑PathType with “leaf” as its value, and the cmdlet will return “true” if the path is a file.

Test-path -Path "C:\Temp\Temp*" -pathtype leaf

To validate the network path of a shared folder on a remote computer, use this cmdlet:

Test-Path -Path "\\FileServer\Backup"

  1. Run Netwrix Auditor → Navigate to Reports → Open User Behavior and Blind Spot Analysis → Go to Information Disclosure → Select File Names Containing Sensitive Data → Click View.
  2. Specify the following filters and parameters:
  3. Object UNC Path — Specify the path to your file share
  4. Disallowed Words — Specify the string you want to search for in filenames
  5. Click View Report.
How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (6)

To save the report, click the Export button → Select a format, such as PDF → Click Save as → Choose the desired location.

Learn more about Netwrix Auditor for Windows File Servers

Find Your Sensitive Files — and Get Critical Details about Them, Too

To maintain security and compliance, IT pros need to regularly search for files that might contain sensitive data and move them to a secure location.You can find and move files manually using Windows Explorer, but this method takes a lot of time so it is useful mainly when you needto secure a single file. To check multiple files more efficiently, you can use PowerShell. However, a PowerShell script for moving files will terminate with an error if the path is invalid, so before you run it, you need to meticulously check whether the files and folders exist, as shown in the examples above.

Instead of spending all that time writing and running scripts, wouldn’t you rather simply open a prebuilt report that checks whether your sensitive data is stored only in proper locations? Try Netwrix Auditor for Windows File Servers. It’s not just easier — you also get a lot more information. In addition to the object path, you’ll see the file ownership details, user access permissions and activity around the file.

Previous How-to How to Find Duplicate Files Next How-to How to Count Files in a Folder or a Directory

Related How-tos

How to Detect File Changes in a Shared Folder How to Detect Who Changed a File or Folder Owner How to Detect Who Tried to Modify a File or a Folder on Your Windows File Server How to Track Who Deleted a File from Your Windows File Servers How to Export Folder Permissions to Excel or CSV File How to Get an NTFS Permissions Report

How to Find a File and Check If It Exists with Powershell or Netwrix Auditor (2024)
Top Articles
Google Clarifies How Helpful Content System Works
Advantages and Disadvantages of Internet Banking | DBS Bank
Kmart near me - Perth, WA
855-392-7812
Www.craigslist Augusta Ga
CA Kapil 🇦🇪 Talreja Dubai on LinkedIn: #businessethics #audit #pwc #evergrande #talrejaandtalreja #businesssetup…
Produzione mondiale di vino
Skip The Games Norfolk Virginia
Stream UFC Videos on Watch ESPN - ESPN
Obituary | Shawn Alexander | Russell Funeral Home, Inc.
Lonadine
Echo & the Bunnymen - Lips Like Sugar Lyrics
Playgirl Magazine Cover Template Free
How Much Are Tb Tests At Cvs
Juicy Deal D-Art
Orange Pill 44 291
Self-Service ATMs: Accessibility, Limits, & Features
Winco Employee Handbook 2022
LCS Saturday: Both Phillies and Astros one game from World Series
Kingdom Tattoo Ithaca Mi
Understanding Gestalt Principles: Definition and Examples
Dove Cremation Services Topeka Ks
1979 Ford F350 For Sale Craigslist
Jersey Shore Subreddit
Login.castlebranch.com
Turns As A Jetliner Crossword Clue
Pioneer Library Overdrive
Uno Fall 2023 Calendar
49S Results Coral
Parent Management Training (PMT) Worksheet | HappierTHERAPY
R/Sandiego
What are the 7 Types of Communication with Examples
Six Flags Employee Pay Stubs
Skroch Funeral Home
Haley Gifts :: Stardew Valley
Darrell Waltrip Off Road Center
Closest 24 Hour Walmart
Louisville Volleyball Team Leaks
Wsbtv Fish And Game Report
Uvalde Topic
Bunkr Public Albums
Unitedhealthcare Community Plan Eye Doctors
Memberweb Bw
Gli italiani buttano sempre più cibo, quasi 7 etti a settimana (a testa)
26 Best & Fun Things to Do in Saginaw (MI)
Tyco Forums
Gummy Bear Hoco Proposal
Turning Obsidian into My Perfect Writing App – The Sweet Setup
Coldestuknow
Shad Base Elevator
Generator für Fantasie-Ortsnamen: Finden Sie den perfekten Namen
Latest Posts
Article information

Author: Edmund Hettinger DC

Last Updated:

Views: 6792

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Edmund Hettinger DC

Birthday: 1994-08-17

Address: 2033 Gerhold Pine, Port Jocelyn, VA 12101-5654

Phone: +8524399971620

Job: Central Manufacturing Supervisor

Hobby: Jogging, Metalworking, Tai chi, Shopping, Puzzles, Rock climbing, Crocheting

Introduction: My name is Edmund Hettinger DC, I am a adventurous, colorful, gifted, determined, precious, open, colorful person who loves writing and wants to share my knowledge and understanding with you.