string - Poweshell concatenation order with function variables and literals -


i'm not sure if mad or missing trying simple pipe separate load of variables in function , write them out.

"easy" say? have thought so. here wee extract of attempts write powehell function make rest of code little easier on eye.

$logtofile=$false function logentry($entrytype, $section, $message) {      #the way assumed woudl work     $logstring1 = $(get-date -format "yyyy-mm-dd hh:mm:ss") + "|" + $entrytype + "|" + $section + "|" + $message     #another way should work     $logstring2 = "$(get-date -format "yyyy-mm-dd hh:mm:ss")|$entrytype|$section|$message"     #proof not pipes causing issues     $logstring3 = "$(get-date -format "yyyy-mm-dd hh:mm:ss"),$entrytype,$section,$message"     #another method found. not sure issue there     $logstring4 = $(get-date -format "yyyy-mm-dd hh:mm:ss"), $entrytype, $section, $message -join "|"     $whatiwant = $(get-date -format "yyyy-mm-dd hh:mm:ss") + "|0|moonin|plimsole"      if($script:logtofile)     {         add-content $logfile $logstring     }     else     {         write-host $logstring1         write-host $logstring2         write-host $logstring3         write-host $logstring4         write-host $whatiwant     } } logentry(0,"moomin","plimsole") 

output:

2011-02-17 11:22:59|system.object[]|| 2011-02-17 11:22:59|0 moomin plimsole|| 2011-02-17 11:22:59,0 moomin plimsole,, 2011-02-17 11:22:59|0 moomin plimsole|| 2011-02-17 11:22:59|0|moonin|plimsole 

searching around found several alternatives, none of seem produce right results. i'm not sure whole "lump of variables space separated" thing in first place.

you're calling function incorrectly. putting 0, mommin, , plimsole first variable, , nothing second , third variables. hence, output getting.

instead of calling function this

logentry(0,"moomin","plimsole") 

you need call function this

logentry 0 "moomin" "plimsole" 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -