PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,328 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
How can this be achieved. I have string values passed to a parameter of a function, and as you can see the allowable values match the start of the variable counters. So instead of this:
switch( $Result ) {
"Info" { $Script:InfoMsgCount++ }
"Success" { $Script:SuccessMsgCount++ }
"Warning" { $Script:WarningMsgCount++ }
"Error" { $Script:ErrorMsgCount++ }
}
do this:
if( $Result -ne "Default ) { $ResultMsgCount++ }
Try this.
if( $Result -ne "Default" ) { Invoke-Expression ('$script:' + $Result + "MsgCount++") }