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
Post a Comment