Private/Write-VMVerbose.ps1
function Write-VMVerbose { <# .SYNOPSIS Writes messages to the verbose message stream. .DESCRIPTION The `Write-VMVerbose` cmdlet writes messages to the verbose output stream. The status messages are prefixed by a header that includes the name of the function referenced in the status message, the subcategory of status message and the status message. .PARAMETER FunctionName Specifies the VMConnectConfig function name. The acceptable values for this parameter are: -- Get-VMConnectConfig -- New-VMConnectConfig -- Remove-VMConnectConfig -- Reset-VMConnectConfig -- Edit-VMConnectConfig -- Test-VMConnectConfig .PARAMETER Category Specifies the subcategory of verbose message. The acceptable values for this parameter are: Constructing Deleting Error Reading Testing Warning Writing .PARAMETER Message Specifies the message to display. This parameter is required. .EXAMPLE Write-VMVerbose -FunctionName Remove-VMConnectConfig -Category Deleting -Message 'This is a VMVerbose warning message.' This command will output the following to the Verbose stream: VERBOSE: [Remove-VMConnectConfig] <Deleting> This is a VMVerbose warning message. .INPUTS System.String You can pipe a string that contains the message to this cmdlet. .OUTPUTS None This cmdlet returns no output. It only writes to the verbose message stream. .NOTES VMVerbose messages are returned only when the command uses the Verbose common parameter. #> param ( [Parameter(Mandatory, Position = 1)] [ValidateSet('Constructing', 'Deleting', 'Error', 'Reading', 'Testing', 'Warning', 'Writing')] [System.String]$Category, [Parameter(Mandatory, Position = 0)] [ValidateSet('Get-VMConnectConfig', 'Edit-VMConnectConfig', 'Reset-VMConnectConfig', 'Remove-VMConnectConfig', 'New-VMConnectConfig', 'Test-VMConnectConfig')] [System.String]$FunctionName, [Parameter(Mandatory, Position = 2, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [System.String]$Message ) # Indent the verbose message string by this many additional spaces (Write-Verbose messages are already padded by 1x space by default). $indentPadLength = 1 # Indentation padding string (blank spaces) in "VERBOSE: [Remove-VMConnectConfig]". $indentString = New-Object -TypeName 'System.String' -ArgumentList ' ', $indentPadLength # The number of spaces between "[FunctionName] <Category>". $padStringLength = 2 # The longest $Category ("<Constructing>") string length is 14 characters. $categoryMaxStringLength = 14 + $padStringLength # The longest $FunctionName ("Remove-VMConnectConfig") string length is 22 characters. $functionStringLengthMax = ((Get-Module -Name VMConnectConfig).ExportedFunctions.Keys | Measure-Object -Maximum -Property Length).Maximum # Padding string (blank spaces) after "[FunctionName] " and "<Category> ". $padString = New-Object -TypeName 'System.String' -ArgumentList ' ', $padStringLength $cat = $Category # WARNING and ERROR categories are in all caps. if ($Category -eq 'Warning' -or $Category -eq 'Error') { $cat = $Category.ToUpper() } # The "+ 2" is to account for the square brackets around the function name. $headerString = ("[" + $FunctionName + "]" + $padString).PadRight(($functionStringLengthMax + 2 + $padString.Length), ' ') $categoryString = ('<' + $cat + '>' + $padString).PadRight($categoryMaxStringLength, ' ') $verboseMessage = $indentString + $headerString + $categoryString + $Message Write-Verbose -Message $verboseMessage } #function Write-VMVerbose |