Ok… This code does everything I need it to do. The only problem is what I originally asked, this will spit out errors when the csv does not contain a value for any of these props. It continues and completes just fine.
From my research, I would need to check every value for $null remove it or add it to a new hashtable then I’d still need to run another check for the word remove and possibly add it to a separate hashtable. It just seems like a lot of overhead just to eliminate errors. So I’m torn if I should just suppress the errors or call it good.
I did play around with checking the value like below but when you look at the hashtable it doesn’t seem to have done anything. The blank value is still in the table.
if ($user.pager) {$hash.add(“pager”, $($user.pager))}
Name Value
state AU
pager remove
samaccountname testguy
state Ma
pager pager1234
samaccountname testguy2
state mo
pager
samaccountname erererer
$props = 'description','office','OfficePhone','mail','WWWHomePage','StreetAddress','POBox',
'l','st','PostalCode','Country','ProfilePath','ScriptPath','HomeDirectory','HomePhone','Pager','Mobile','ipphone','otherFacsimileTelephoneNumber','otherHomePhone','otheripphone',
'otherMobile','otherpager','title','company','department','proxyaddresses'
Import-CSV c:\it\bulk_edit.csv |
ForEach-Object {
$u = Get-ADUser $_.samaccountname -Properties $props
#the $_. can match what is in the csv file
$u.description = $_.description
$u.office = $_.office
$u.OfficePhone = $_.officephone
$u.mail = $_.officephone
$U.WWWHomePage = $_.webpage
$U.StreetAddress = $_.street
$u.POBox = $_.pobox
$u.l = $_.city
$u.st = $_.stateprovince
$u.PostCode = $_.zip
$u.Country = $_.county
$u.ProfilePath = $_.profilepath
$u.ScriptPath = $_.logonscript
$u.HomeDirectory = $_.homedirectory #needs to be drive letter/folder
$u.HomePhone = $_.homephone
$u.Pager = $_.pager
$u.Mobile = $_.mobile
$u.ipphone = $_.ipphone
$u.otherFacsimileTelephoneNumber = $_.otherfaxnumber
$u.otherHomePhone = $_.otherhomephone
$u.otheripphone = $_.otheripphone
$u.otherMobile = $_.othermobile
$u.otherpager = $_.otherpager
$u.title = $_.jobtitle
$u.company = $_.company
$u.department = $_.department
$u.proxyaddresses = $_.proxyaddresses
if ($u.description -contains 'remove')
{Set-ADUser $_.samaccountname -clear @{description=$u.description}} else {Set-ADUser -identity $_.samaccountname -replace @{description=$u.description}}
if ($u.office -contains 'remove')
{Set-ADUser $_.samaccountname -clear @{office=$u.office}} else {Set-ADUser -identity $_.samaccountname -replace @{office=$u.office}}
if ($u.state -contains 'remove')
}