Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Powershell阵列导出不相等运算符不工作_Arrays_Powershell_Export To Csv_Logical Operators - Fatal编程技术网

Arrays Powershell阵列导出不相等运算符不工作

Arrays Powershell阵列导出不相等运算符不工作,arrays,powershell,export-to-csv,logical-operators,Arrays,Powershell,Export To Csv,Logical Operators,我有一个.csv文件,里面有几百条记录,我需要将它们分解成几个不同的文件。代码中有一部分接受对象数组,并根据数组过滤文件。它对于查找与数组中的内容相等的内容的部分非常有效,但是当我尝试根据数组中不包含的内容进行筛选时,它会忽略我可以找到的任何“not equal”操作符版本。我认为这与数据类型有关,但我不明白当equal运算符工作时,为什么会有不同 CSV文件 PowerShell代码 $msaClients = @("Widget, Inc","Johns Company") $billing

我有一个.csv文件,里面有几百条记录,我需要将它们分解成几个不同的文件。代码中有一部分接受对象数组,并根据数组过滤文件。它对于查找与数组中的内容相等的内容的部分非常有效,但是当我尝试根据数组中不包含的内容进行筛选时,它会忽略我可以找到的任何“not equal”操作符版本。我认为这与数据类型有关,但我不明白当equal运算符工作时,为什么会有不同

CSV文件 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
我尝试了所有不同的逻辑运算符来表示notequal,但它似乎忽略了这一部分。如果有什么不对劲,我还有更多的代码要写


我错过了什么,提前谢谢你的帮助

如果我理解正确,您需要$MSARRAY中的值,其中$billingList包含存在于$msaClients中的CustomerID,但其相应的记帐时间不应等于$idzero(在本例中为0)

对于$laborArray,其中$billingList不包含存在于$msaClients中的CustomerID,其相应的记帐时间也不应等于$idzero(在本例中为0)

您的-ne操作符正在工作,但您在$msaclients中循环太多次,无法获得$laborArray。即,当$msa=“Widget,Inc.”输出为“Mars Bars,Inc.”时,foreach循环再次运行,$msa值更改为“Johns Company”,在本例中,输出为“Mars Bars,Inc.”和“Widget,Inc.”。因此,您得到了三个输出

$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
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
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