我注意到在PowerShell中调用函数时,我无法在就地格式化字符串。我需要格式化它,因为我想输出一个十六进制数而不是十进制数。
这并没有这样做:
WriteLog "Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices
它只有在我将结果存储在变量中然后像这样使用它时才有效:
$Log = "Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices
WriteLog $Log
如果有办法在一个陈述而不是两个陈述中做到这一点吗?
答案 0 :(得分:2)
把它放在括号中:
WriteLog ("Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices)