완전히 화나거나 누락 된 항목인지 모르겠지만 파이프에서 함수의 변수로드를 분리하고 작성하는 매우 간단한 작업을 수행하려고합니다.함수 변수와 리터럴을 사용하는 Poweshell 연결 순서
"쉬운"라고 말할까요? 나는 그렇게 생각했을 것이다. 그러나 나머지 코드를 눈에 좀 더 쉽게 만들 수있는 powehell 함수를 작성하려는 나의 시도를 요약 한 것입니다.
$logtoFile=$false
function logEntry($entryType, $section, $message)
{
#The way I assumed woudl work
$logString1 = $(get-Date -format "yyyy-MM-dd hh:mm:ss") + "|" + $entryType + "|" + $section + "|" + $message
#Another way which should also work
$logString2 = "$(get-Date -format "yyyy-MM-dd hh:mm:ss")|$entryType|$section|$message"
#Proof that it is not the pipes causing issues
$logString3 = "$(get-Date -format "yyyy-MM-dd hh:mm:ss"),$entryType,$section,$message"
#another method I found. Not sure what the issue is 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")
출력 :
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
내가 올바른 결과를 생성하는 것 어느 것도 몇 가지 대안을 찾아 주위를 검색. 나는 "전체 변수들이 모두 공간 분리되어있다"라는 것이 전체적으로 무엇인지 잘 모르겠습니다.
이 글은 올리려고했지만 나를 때렸습니다. 이러한 변화를 통해 세 번째 접근 방식을 제외한 모든 방식이 예상되는 결과를 제공합니다. –
DOH! 나는 커맨드 라인에서 너무 오래 떨어져 있었다. – Bodestone
댓글을 잊어 버린 경우는 캐리지 리턴을받을 수 없어 일찍 제출하십시오. 고마워. 필자가 수년간 사용해온 다른 모든 방식의 구문 Sunce를 호출하는 함수를 확인하는 일은 결코 내게 발생하지 않았습니다. 아무도 없었기 때문에 연결 문제에 아무 것도 없었던 것은 당연합니다. – Bodestone