Splitting CSV cell (but leave the original as is) using Powershell -
i'm trying add pdf's files directory csv file.
i'm using below powershell script add pdfs issue need split (but leave original pdf path on each file is) path numbers calls.
is there way accomplish one?
get-childitem -recurse "c:\users\alon\desktop\mypdf\" | foreach-object { $_ | add-member -name "owner" -membertype noteproperty -value (get-acl $_.fullname).owner -passthru } | sort-object fullname | select fullname, creationtime, lastwritetime, length, owner | export-csv -force -notypeinformation "c:\users\alon\desktop\mypdf\directory.csv"
the output should this:
you mean want add numbers filename additional fields in output? split each file's basename , construct custom objects information , file metadata:
get-childitem ... | foreach-object { $numbers = $_.basename -split '_' [pscustomobject]@{ fullname = $_.fullname company = [int]$numbers[0] invoice = [int]$numbers[1] deal = [int]$numbers[2] customer = [int]$numbers[3] autonumber = [int]$numbers[4] creationtime = $_.creationtime lastwritetime = $_.lastwritetime length = $_.length owner = (get-acl $_.fullname).owner } | sort-object fullname | export-csv ...
using calculated properties work, in case constructing new objects arguably simpler approach.
note [pscustomobject]
type accelerator requires powershell v3 or newer. on older versions can create objects via new-object
, use select-object
properties in defined order.
Comments
Post a Comment