I seem to be having a weird permission issue with active directory. The user that is running this script has access to change active directory atributes and is able to do it from the command line, but unable to run the command inside of the script.
The command im trying to run is this:
Set-ADUser -identity $user.DistinguishedName -replace @{info="1"}
this command runs and executes fine inside of the Powershell command line. The command line is also being ran as the user that runs the script. So the user has has the right permission to change active directory attributes. However, when i put this command in the script, I get a permission issue.
Inside of my script this is the block that gets the error:
try{
Set-ADUser -identity $user.DistinguishedName -replace @{info="1"}
Set-ADUser -identity $username -replace @{employeeID="<not set>"}
Logwrite "Employee ID: Cleared!"
}
catch{
#Update Log Of Error
$errorcountforemail = $errorcountforemail + 1
logwrite "Employee ID:******* [FAILED] *******"
$errortest = $_
Write-Output $_
Out-File -FilePath $logfile2 -Append -InputObject "`n" -Encoding ascii -Width 50
Out-File -FilePath $logfile2 -Append -InputObject "Problem setting ad user for $username" -Encoding ascii -Width 50
Out-File -FilePath $logfile2 -Append -InputObject $_ -Encoding ascii -Width 50
Out-File -FilePath $logfile2 -Append -InputObject "`n" -Encoding ascii -Width 50
}
This is the Error with the names changed for confidentiality.
*---------------------* Errors for: ############## *---------------------*
Problem setting ad user for ################
Set-ADUser : Insufficient access rights to
perform the operation
At C:\##################.ps1:199 char:13
+ Set-ADUser -identity
$user.DistinguishedName -replace @{ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified:
(#########################:ADUser)
[Set-ADUse r], ADException
+ FullyQualifiedErrorId : ActiveDirectoryServe
r:8344,Microsoft.ActiveDirectory.Management.Com
mands.SetADUser
Things i have tried:
-running as admin and with highest privileges.
-starting the script in a batch file that runs it as admin
-forcing credentials like this:
Set-ADUser -identity $user.DistinguishedName -credentials $domaincredential -replace @{info="1"}
with the credentials of this user because it does have access to make these changes.
Any thoughts?
.ps1file and then have the user run the.ps1file. If it works that way, then the problem is obviously elsewhere. - Bill_StewartImport-Module activedirectory try{ Set-ADUser -Identity mdecarlo -Replace @{info="1"} } catch{ Write-Output $_ }- Matthew Decarlo