Ido Ran
Ido Ran

Reputation: 11374

Format string inplace in PowerShell

I've notice I'm not manage to format string in-place when calling a function in PowerShell. I need to format it because I want to output a number as hex and not decimal.

This didn't work like so:

WriteLog "Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices

It only works if I store the result in variable and then use it like so:

$Log = "Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices
WriteLog $Log

If there a way to do it in one statement instead of two?

Upvotes: 0

Views: 164

Answers (1)

briantist
briantist

Reputation: 47792

Just put it in parentheses:

WriteLog ("Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices)

Upvotes: 2

Related Questions