excel - Export-CSV only gets the "Length" -
when try export csv list, number "length" .count
property until split point reached, split csv array new file new name used point on. might issue?
$rootfolder = get-content "c:\drivers\myfile.txt" foreach ($arrayofpaths in $rootfolder){ $csv = $arrayofpaths -replace '^\\\\[^\\]+\\([^\\]+)\\([^\\]+).*', 'c:\output\company_name_${1}_${2}.csv' $csvindex = 1 $maxrows = 1000000 $rowsleft = $maxrows get-childitem $arrayofpaths -recurse | where-object {$_.mode -match "d"} | foreach-object { #$csv = $_.fullname -replace '^\\\\[^\\]+\\([^\\]+)\\([^\\]+).*', 'c:\output\company_name_${1}_${2}.csv'# <- construct csv path here $path = $_.fullname $thiscsv = get-acl $path | select-object -expand access | select-object @{n='path';e={$path}}, identityreference, accesscontroltype, filesystemrights | convertto-csv if ($thiscsv.count -lt $rowsleft) { $thiscsv | export-csv $csv -append -notype $rowsleft -= $thiscsv.count } else { $thiscsv[0..($rowsleft - 1)] | export-csv $csv -append -notype $csvindex++ $csv = $csv -replace '\.csv$', "$csvindex.csv" if ($thiscsv.count -gt $rowsleft) { $thiscsv[$rowsleft..($thiscsv.count - 1)] | export-csv $csv -append -notype } $rowsleft = $maxrows - ($thiscsv.count - $rowsleft) } } }
export-csv
built take pscustomobjects input, not lines of text.
$thiscsv = get-acl $path | select-object -expand access | select-object @{n='path';e={$path}}, identityreference, accesscontroltype, filesystemrights | convertto-csv
the output of line like:
#type selected.system.security.accesscontrol.filesystemaccessrule "path","identityreference","accesscontroltype","filesystemrights" "c:\test","builtin\administrators","allow","fullcontrol"
at least 3 lines, array of string. properties array of string have?
ps c:\> 'a','b' | get-member -membertype property typename: system.string name membertype definition ---- ---------- ---------- length property int length {get;}
length. property see in csv, because export-csv exporting properties, , that's property.
fix: remove | convertto-csv
get-acl
line, leave custom objects custom objects , let export handle converting them.
(this should fix counting, because it's not counting 3+ lines of text while trying export 1+ line of data every time).
Comments
Post a Comment