Skip Blank Values in Import-CSV
i attempting mass import of user attributes (phone number, address, city, state, zip code, title, company). goes until hit blank value in csv. here powershell script trying use.
import-csv ia-test2.csv | foreach-object { $record = $_ get-aduser -ldapfilter "(samaccountname=$($record.samaccountname))" | set-aduser -city $record.l -postalcode $record.postalcode -officephone $record.officephone -company $record.company -streetaddress $record.streetaddress -title $record.title } how can modify skip blank values?
typo. i missing last $ in
{ $params.$property = $_.property } updated script:
$properties = @( 'city', 'postalcode', 'officephone', 'company', 'streeaddress', 'title' ) import-csv ia-test2.csv | foreach-object { $params = @{} foreach ($property in $properties) { if ($_.$property) { $params.$property = $_.$property } } get-aduser -ldapfilter "(samaccountname=$($_.samaccountname))" | set-aduser @params } [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
Windows Server > Windows PowerShell
Comments
Post a Comment