Powershell Check If File Contains String

I am looking to find a string in word and excel document E.g Like 'Security' if it contains in any of the document, the same should be moved to other location.can anyone suggest with simple scripts pls.!! This simple script worked in finding and relocating the file, but it is not working for docx format, pls help out. Check if String contains '.' (Character rather than wildcard) Welcome › Forums › General PowerShell Q&A › Check if String contains '.' (Character rather than wildcard) This topic has 3 replies, 3 voices, and was last updated 3 years, 7 months ago.

  • Related Questions & Answers
Powershell
  • Selected Reading
PowerShellMicrosoft TechnologiesSoftware & Coding
Powershell check if file contains string file

To check if the file is empty using PowerShell, we can use the string method called IsNullorWhiteSpace(). This method provides result true if the file is empty or only contains the white spaces otherwise false.

For example, We have a test2.txt text file which has whitespaces.

Example

Output

But if you have a file like CSV which contains few headers but the data is empty, in that case, Get-Content will show the wrong output because it will consider headers. For example,

Example

Output

Because the file has headers.

In that case, we can use the Import-CSV command inside the brackets.

Powershell Check If File Name Contains String

Example

Powershell Check If Array Contains String

Output