How to extract columns from PowerShell


hello,

i new powershell programming.  i want extract ad information providing input <g class="gr_ gr_127 gr-alert gr_spell gr_run_anim contextualspelling ins-del multireplace" data-gr-id="127" id="127">csv</g> file user's first , last name.  i don't know how extract first , last name column 2 different variables powershell query ad givename , surname.  

below powershell script wrote.  where firstname , lastname should come <g class="gr_ gr_997 gr-alert gr_spell gr_run_anim contextualspelling ins-del multireplace" data-gr-id="997" id="997">adtest</g>.<g class="gr_ gr_1010 gr-alert gr_spell gr_run_anim contextualspelling ins-del multireplace" data-gr-id="1010" id="1010">csv</g> input rows.  

any suggestion?

adtest.csv file:

brandon ho

jerry smith

import-module activedirectory    $aresults = @()  $list = get-content "c:\temp\adtest.csv"          foreach($item in $list){      $item = $item.trim()      $user = get-aduser -filter {givename -like 'firstname' -and surname -like 'lastname'} -properties samaccountname, userprincipalname        $hitemdetails = new-object -typename psobject -property @{              displayname = $item           loginid     = $user.samaccountname          email       = $user.userprincipalname      }           $aresults += $hitemdetails  }  $aresults | export-csv "c:\temp\results.csv"  

hi brandon,

you want import-csv instead of get-content reading in input file.

http://ss64.com/ps/import-csv.html




Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

some help on Event 540

WMI Repository 4GB limit - Win 2003 Ent Question

Event ID 1302 (error 1307) DFS replication service encountered an error while writing to the debug log file