powershell PowerShell中的Csv

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell中的Csv相关的知识,希望对你有一定的参考价值。

## rsp_freight_margin_extract
## cd D:\Temp\rsp_freight_margin_extract-2018-10-05-13-09-10\Production
## gci *.csv | % { Format-ProductionTestCasesForComparison $_ }
function Format-ProductionTestCasesForComparison {
    param([string]$originalFile)

    $newFileName = (Get-ChildItem $originalFile | % { "$($_.DirectoryName)\$($_.BaseName)-CommonColumnHeaders$($_.extension)"})
    import-csv $originalFile |
    select -property consignment_number,
        shipment_number,
        consignment_status,
        owner,
        carrier,
        subcontractor,
        vehicle,
        zone_from,
        zone_to,
        pickup_name,
        delivery_name,
        actual_departure_date,
        actual_delivered_date,
        movement_date,
        weight,
        volume,
        @{name='LiftQty';expression={$_.qty1}},
        @{name='PalletQty';expression={$_.qty2}},
        @{name='CartonQty';expression={$_.qty3}},
        item_desc,
        customer_charge,
        cust_charge_uom_qty,
        cust_charge_uom,
        customer_invoice,
        customer_invoice_amt,
        supplier_charge,
        supp_charge_uom_qty,
        supp_charge_uom,
        supplier_invoice,
        supplier_invoice_amt,
        booking_ref,
        po_number,
        margin_dollar,
        margin_percentage,
        protection_type |
    sort -property consignment_number |
    export-csv -notype -literalpath $newFileName
}

invoke-sqlcmd -ServerInstance "serverpath,port#" -Username sa -Password (read-host) -Database Ascend_AU -Query "select * from Location " | export-csv -NoTypeInformation d:\temp\Locations.csv 
$thisSide = (import-csv "somefile.csv")
$thatSide = (import-csv "otherfile.csv")
compare-object -ReferenceObject $thisSide -DifferenceObject $thatSide | ? { $_.SideIndicator -eq '<=' } 

以上是关于powershell PowerShell中的Csv的主要内容,如果未能解决你的问题,请参考以下文章

如何仅在 VS 2012 中的 Web 部署发布任务之前执行 PowerShell 脚本?

Visual Studio下运行PowerShell脚本自动更新项目里AssemblyInfo.cs文件的版本(自增小版本号)并发布到Nuget服务器上

Windows powershell 自学指南1

使用powershell通过配置文件config调用wcf(含用户名密码认证)

CS Ink钓鱼

将外部 C# 脚本作为源添加到 PowerShell 脚本