how to handle - import-csv results

Dear experts
I have this command $Items = Import-Csv -path "$CsvFile" -Encoding UTF8 –delimiter ";"

This work pretty well so I can access the collection by having the fieldnames etc.... ($Items.<fieldname> is OK)

BUT how to have a global view ? How to know for $Items, the number of elements?

François VDCIcT service DeskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Open in new window

François VDCIcT service DeskAuthor Commented:
$items.count return nothing.

 write-host $items
@{IDENTIFIANT=900000003; TITLE_CODE=; TITLE_NAME=; CONTRAT_NB=900000003; NAME=AO; FIRSTNAME=Stagiaire; SEXE=; NATIONAL_ID=; STREET=; STREET_NR=; STREET_BOX=; CITYCODE=; CITY NAME=; COUNTRY NAME=; PHONE_PROF=; GSM_PROF=;; BIRTHDATE=; NATIONALITY NAME=; LANG=; WORKERLANG NAME=; TRY_DATE=; ENTRY_DATE=20171130; OUT_DATE=; CONTRAT_TYPE=; CONTRAT_TYPE_NAME=; FTE=; FUNCTION=Stagiaire; AGE=; CODE_DEPARTEMENT=; DEPARTEMENT=; IDENTIFIANT_RESPONSABLE=; LOGIN_RESPONSABLE=sgoossens; RESPONSABLE=; LOGIN=stao; CODE_EMPLOYEUR=51300; CODE_SITE=AO; SITE=; EmployeeName=Stagiaire AO; SignaletiqueInsert=20171130; SignaletiqueUpdate=; AddressInsert=; AddressUpdate=; AffectationInsert=; AffectationUpdate=; ContractInsert=; ContractUpdate=; GAP=; Matchbox=; SMILE=; Intranet=; Desktop=; Laptop=; Carte_De_visite=; telephone=; GSM=; Smartphone=; Signal=; VPN=; clee_jobcenter=; ProxBudget=; Analytique1Code=; Analytique2Code=; IN=TRUE; OUT=}

write-host $items.count

return nothing
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
And of course you can just dump everything with $items | format-table -auto or $items | format-list, to see what is in the collection.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That is a single object, no collection. @($Items).Count works though. It forces the content to be an array, and that array always has a Count member.
François VDCIcT service DeskAuthor Commented:
yes indeed Qlemo, but I want to have the number of items on this collection/hashtable what is this object.
François VDCIcT service DeskAuthor Commented:
@($Items).Count report 1 not the count of all elements....
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
That is a different beast. You want to know the number of (custom) properties of that custom object ...
A hashtable would allow for counting, e.g. @{a=1;b=2}.Count.
François VDCIcT service DeskAuthor Commented:
Ok. I'm still lost....
how may I know the number of custom properties that has a custom object? (from the import-csv cmdlet) Purpose is dataquality check (see if I have the number of col that I expect)
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Here you go: @($items.PsObject.Properties).count
The hidden PsObject property allows for direct access to the underlaying object structure.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
François VDCIcT service DeskAuthor Commented:
Your'e brillant !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.