在PowerShell中就地设置字符串格式

在PowerShell中就地设置字符串格式,powershell,Powershell,我注意到在PowerShell中调用函数时无法将字符串格式化到位。我需要格式化它,因为我想输出十六进制而不是十进制的数字 这不是这样的: WriteLog "Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices WriteLog ("Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices) 仅当我将结

我注意到在PowerShell中调用函数时无法将字符串格式化到位。我需要格式化它,因为我想输出十六进制而不是十进制的数字

这不是这样的:

WriteLog "Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices
WriteLog ("Running Step | Retry=$RetryCount | EnabledDevices={0:X}" -f $EnabledDevices)
仅当我将结果存储在变量中,然后像这样使用它时,它才起作用:

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

如果有一种方法可以在一个语句中而不是两个语句中完成,只需将其放在括号中即可: