Assert-Empty

Checks that an object is empty.

Syntax

Assert-Empty [[-InputObject] <Object>] [[-Message] <String>] [<CommonParameters>]

Description

This checks that an object's Length or Count property is equal to 0. That means this function should be used with strings or collections, or similar objects.

Parameters

Name Type Description Required? Pipeline Input Default Value
InputObject Object

The object to check.

false false
Message String

A descriptive message to show if the object isn't empty.

false false

EXAMPLE 1

Assert-Empty ''

Demonstrates how to check if a string is empty, which in this case it is.

EXAMPLE 2

Assert-Empty @()

Demonstrates that collections can be checked as well as strings.

EXAMPLE 3

Assert-Empty @{ Foo = 'Bar' } 'Settings not initialized.'

Demonstrates how to show your own message when the assertion fails.