PS – bulk-import of AD-Users with skipping blank values

In the following example an bulk-import of AD-Users is done. The clever thing – blank parameters will be skipped. A condition for this to work properly is that the the headers of the csv-file must match the names in the AD.

Import-Module ActiveDirectory
$users = Import-Csv -Path C:\temp\export\workspace.csv
foreach ($user in $users) {
    $properties = @{}
    $user | Get-Member -Type NoteProperty | Select -Expand Name | Foreach {
        if ($user."$_") { $properties.Add("$_", $user."$_") }
    Set-ADUser -Identity $user.sAMAccountName @properties -Verbose