Assert-FileContains

Asserts that a file contains another string.

Syntax

Assert-FileContains [[-Path] <String>] [[-Needle] <String>] [[-Message] <Object>] [<CommonParameters>]

Description

Performs a case-sensitive check for the string within the file.

Parameters

Name Type Description Required? Pipeline Input Default Value
Path String

The path to the file.

false false
Needle String

The string to look for. Case-sensitive.

false false
Message Object

A description about why the assertion might have failed.

false false

EXAMPLE 1

Assert-FileContains 'C:\Windows\System32\drivers\etc\hosts' '127.0.0.1'

Demonstrates how to assert that a file contains a string.

EXAMPLE 2

Assert-FileContains 'C:\Windows\System32\drivers\etc\hosts' 'doubclick.net' 'Ad-blocking hosts entry not added.

Shows how to use the Message parameter to describe why the assertion might fail.