In PowerShell 5.0 and higher, an object instance may be created using the new static method:
$stringBuilder = [System.Text.StringBuilder]::new()
For earlier versions of PowerShell, the object instance may be created using:
$stringBuilder = New-Object System.Text.StringBuilder
PowerShell has added the static method (discussed later in this chapter); it can be used if required, but it is not documented on the MSDN page for StringBuilder.
Once an instance of StringBuilder has been created, it can be viewed:
PS> $stringBuilder = New-Object System.Text.StringBuilder
$stringBuilder
Capacity MaxCapacity Length
-------- ----------- ------
16 2147483647 0
The StringBuilder object has a number of other constructors. These are used to adjust the initial state of the instance.