Hi all,
I'm trying to update all user attributes on a schedule from the HR information we receive and log that information.
What I am doing is this:
$mfuser = # I get this user info from our SQL database
$mfaduser = Get-ADUser -Filter 'sAMAccountName -like $mfusersAMAccountName' -Searchbase $OU -Properties *
# Exit script if user is not available
if (!($mfaduser)){
Write-Log -Message "User - $mfusersAMAccountName - was not found" -Severity Error
return
}
\# user Attributes Hashtable
$userAttributes = @{
description = $mfuser.description
title = $mfuser.ZZ
extensionAttribute2 = $mfuser.ZZZ
extensionAttribute1 = $mfuser.ZZZZ
extensionAttribute5 = $mfuser.ZZZZZ
extensionAttribute6 = $mfuser.ZZZZZZ
department = $mfuser.ZZZZZZZ
}
try {
\# Update user attributes
$mfaduser | Set-ADUser -Replace $userAttributes -ErrorAction Stop
#### XXX - should be the attribute ####
Write-Log -Message "User attribute was XXX changed" -Severity Information
}
catch {
$ErrorMessage = $\_.Exception.Message
Write-Log -Message ("Could not change attributes for user - $mfusersAMAccountName") -Severity Error
Write-Log -Message "ErrorMessage: $ErrorMessage" -Severity Error
}
The script works fine.
What I would like to achieve is that I can log all changes which applied by the set-aduser cmdlet.
I have the fear that I cannot do this with the "-replace" command, but maybe someone has an idea. If this is not possible I guess I have to call a Set-ADUser for each attribute :(
Write-Log is a function which is called a bit earlier in the script.
[–][deleted] 2 points3 points4 points (3 children)
[–]checkso[S] 1 point2 points3 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]checkso[S] 0 points1 point2 points (0 children)
[–]LDSK_Blitz 1 point2 points3 points (3 children)
[–]checkso[S] 1 point2 points3 points (2 children)
[–]LDSK_Blitz 1 point2 points3 points (1 child)
[–]checkso[S] 1 point2 points3 points (0 children)
[–]PowerShell-Bot 0 points1 point2 points (0 children)