Home > Mobile >  How do condition mid-string
How do condition mid-string

Time:05-12

I have a string in my psobject and it will only apply for 10 devices but not the 11th one. How do I construct a string and not include one variable if it's the 11th one?

This is what works for the first 10 in my foreach:

$INFO_Tab = New-Object psobject -Property $([ordered]@{
                DEVICE = "$($currentDevice)"
                Platform = "Name"
                Device_Error_Description = "ErrorCodeList files \Retail\Tools\ServiceEndToEnd\ErrorCodeList "
                OCP_Display = "sdkDesc in $BaseName $($cppFile)" #$BaseName doesn't apply for $currentDevice="Scanner"
                ...
})
$xlsx = $INFO_Tab | Export-Excel -Path $outFilePathExcel -WorksheetName "Source" -Autosize -AutoFilter -FreezeTopRow -BoldTopRow  -PassThru

Can I do something like this for the OCP_Display line? I can't find an example.

OCP_Display = "sdkDesc in"  if($currentDevice="Scanner"):"":$BaseName  $($cppFile)"

This is with PowerShell 5.1 and VSCode.

CodePudding user response:

Wrap the if statement in a subexpression $():

"sdkDesc in $(if($currentDevice -ne 'Scanner'){"$BaseName "})$($cppFile)"
  • Related