Advertisement
Guest User

create object array from csv

a guest
Apr 27th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $ContosoUserArray = @()
  2. $ADUserList = Import-Csv "C:\Scripts\DataFiles\ADUsers.csv"
  3.  
  4. foreach($ContosoUser in $ADUserList)
  5. {
  6.     $SamAccountName = (($ContosoUser.SamAccountName).Trim()).ToLower()
  7.     $UserPrincipalName = (($ContosoUser.UserPrincipalName).Trim()).ToLower()
  8.     $HomeDirectory = (($ContosoUser.HomeDirectory).Trim()).ToLower()
  9.     $EmailAddress = (($ContosoUser.EmailAddress).Trim()).ToLower()
  10.  
  11.     $ContosoUserObj = New-Object –TypeName PSObject
  12.     $ContosoUserObj | Add-Member -type NoteProperty -Name SamAccountName -value $SamAccountName
  13.     $ContosoUserObj | Add-Member -type NoteProperty -Name EmailAddress -value $EmailAddress
  14.     $ContosoUserObj | Add-Member -type NoteProperty -Name HomeDirectory -value $HomeDirectory
  15.     $ContosoUserObj | Add-Member -type NoteProperty -Name UserPrincipalName -value $UserPrincipalName
  16.        
  17.     $ContosoUserArray += $ContosoUserObj
  18. }
  19.  
  20. $ContosoUserArray.count
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement