Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

PowerShell code in a library function

Aug
2,799
144
I am converting a .btm file to a library function,
which contains PowerShell code.

Note that this PowerShell code will not work in a library function.

Code:
if ($inputString.StartsWith('"') -and $inputString.EndsWith('"')) {
    $inputString = $inputString.Substring(1, $inputString.Length - 2) 
}

That's because a library function uses the same structure as the PowerShell code...
Code:
The opening brace { must be on the same line as the function name (separated by a space), and the closing brace } must be on a line by itself.

The solution is to move the closing } in the PowerShell code to the end of the previous line of code...
Code:
if ($inputString.StartsWith('"') -and $inputString.EndsWith('"')) {
    $inputString = $inputString.Substring(1, $inputString.Length - 2) }

Joe
 
Back
Top