2014-04-19 3 views
0

몇 가지 다른 파일로 해부해야 할 몇백 개의 레코드가있는 .csv 파일이 있습니다. 객체의 배열을 취하고 배열을 기반으로 파일을 필터링하는 코드의 일부가 있습니다. 그것은 배열에서 whats와 동일한 것을 발견하는 부분에 대해 훌륭하게 작동하지만, 배열에 포함되지 않은 것을 기반으로 필터링하려고 할 때 찾을 수있는 "같지 않은"연산자의 버전을 무시합니다. 데이터 유형과 관련이 있다고 생각하지만 동등 연산자가 작동 할 때 왜 차이가 나는지 알 수 없습니다. 나는이 동일하지 않은 모든 다른 논리 연산자를 시도하고 그냥 그 부분을 무시하는 것 같다 Powershell 배열 내보내기 같지 않은 연산자가 작동하지 않습니다.

$msaClients = @("Widget, Inc","Johns Company") 
$billingList = import-csv "c:\billing\billed.csv" 
$idZero = "0" 

$msaArray = foreach ($msa in $msaClients) {$billingList | where-object {$_.CustomerID -eq $msa -and $_."Accounted time" -ne $idZero}} 
$laborArray = foreach ($msa in $msaClients) {$billingList | where-object {$_.CustomerID -ne $msa -and $_."Accounted time" -ne $idZero}} 

$msaArray | export-csv c:\billing\msa.csv -notypeinformation 
$laborArray | export-csv c:\billing\labor.csv -notypeinformation 

CSV 파일
"Number","Ticket","Title","Customer User","CustomerID","Accounted time","Billing" 
"1","2014041710000096","Calendar issues","george.jetson","Widget, Inc","0.25","Labor","" 
"2","2014041710000087","Redirected Folder permission","jane.smith","Mars Bars, Inc.","1","Labor","" 
"3","2014041610000203","Completed with No Files Changed ""QB Data""","will.smith","Dr. Smith","0","Labor","" 
PowerShell을 코드입니다. 뭔가 옳지 않은 것처럼 보이면 코드에 훨씬 더 많은 부분이 있습니다.

무엇이 누락 되었습니까? 사전에 도움을 주셔서 감사합니다. 난이 올바른 이해한다면

답변

0

, 당신은 $ billingList에 $ msaClients에 존재하지만 그에 상응 차지 시간 (이 경우 0) $ idzero에 eual 안 customerIDs

을 포함 $ msaArray,의 값을 원하는

그리고 $ billingList에 $ msaClients에 존재하고 그에 상응 차지 시간 (이 경우 0)뿐만 아니라 $ idzero에 eual 안 customerIDs

PS C:\> $laborArray = ($billingList | where {(!($msaclients -contains $_.customerid)) -and ($_.'accounted time' -ne $idZero)}) 
PS C:\> $laborArray | ft -auto 

Number Ticket   Title      Customer User CustomerID  Accounted time Billing 
------ ------   -----      ------------- ----------  -------------- ------- 
2  2014041710000087 Redirected Folder permission jane.smith Mars Bars, Inc. 1    Labor 

를 포함하지 않는 $ laborArray에 대한

PS C:\> $msaArray = ($billingList | where {(($msaclients -contains $_.customerid)) -and ($_.'accounted time' -ne $idzero)}) 
PS C:\> $msaArray | ft -auto 

Number Ticket   Title   Customer User CustomerID Accounted time Billing 
------ ------   -----   ------------- ---------- -------------- ------- 
1  2014041710000096 Calendar issues george.jetson Widget, Inc 0.25   Labor 
귀하 -ne 연산자가 작동 중입니다. , $ msaclients에서 $ laborArray.i.e를 얻기 위해 너무 많은 시간을 반복하고 있습니다. $ msa = "Widget, Inc"일 때, "Mars Bars, Inc." 출력으로,하지만 foreach 루프가 다시 뛰었고 $ msa 값이 "Johns Company"로 변경되었습니다.이 경우에는 "Mars Bars, Inc." 및 "Widget, Inc"도 출력으로 표시됩니다. 그래서 당신은 세 가지 결과물로 끝났습니다.

+0

당신은 절대적으로 흔들어서, 고맙습니다. – user3550556

+0

다행히 도울 수 있어요 :) – Nitesh

관련 문제