February 2019
Intermediate to advanced
626 pages
15h 51m
English
It is possible to cast to System.Void to discard output. When using the StringBuilder example, this is a clean approach:
using namespace System.Text$stringBuilder = [StringBuilder]::new()[Void]$stringBuilder.AppendFormat('Name: {0}', $service.Name).AppendLine(). AppendFormat('Status: {0}', $service.Status).AppendLine(). AppendLine()$stringBuilder.ToString()
However, when used with a command, it requires the use of extra parentheses, which can make it less appealing to use. This example uses Void to suppress the output from the Get-Command command:
[Void](Get-Command Get-Command)
Read now
Unlock full access