Updating CSV cells

Welcome Forums General PowerShell Q&A Updating CSV cells

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 8 months ago.

  • Author
  • #78865

    Topics: 12
    Replies: 16
    Points: 0
    Rank: Member

    Afternoon all.

    I'm trying to update csv cells after finding the right one.. It works on small files but my sheet is 15,000 rows and my script hangs..
    Is there anyway to improve it?

    function bookINGEM {
    $Eng = (get-qaduser $user).displayName
    $DelDate = (Get-Date -format d)
    $Refe = $SerialRef.text
    $file = "C:\temp\Tracker.csv"
    $csv = Import-Csv $file 
    foreach($row in $csv) 
    if ($row.SerialNo -eq $Refe) {
        $row.HostName = $BoxHost.text
        $row.Asset = $BoxAsset.text
        $row.Location = "LOCXXXXXX"
        $row.LifeCycleStatus = "In Stock"
        $row.SubStatus = "Available"
        $row.Date = $DelDate
        $row.Updated = $Eng   
    $csv | Export-Csv  $file -NoTypeInformation;
    $StatusBarPanel.text = "Updated"
  • #78868

    Topics: 1
    Replies: 11
    Points: 1
    Rank: Member

    Hi Andy,
    just change the code from:

    $csv | Export-Csv  $file -NoTypeInformation;


    $csv | Export-Csv  $file -NoTypeInformation;

    So in other words, just move output to the file out of the foreach loop and update only at the end, and it will take you a blink of an eye to complete the update

The topic ‘Updating CSV cells’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort