I have made this script:
$startDTM = (Get-Date) $path = Split-Path -parent "C:\a" $logdate = Get-Date -Format ddmmyyyy $userdisableddate = Get-Date $csvfile = $path + "a\User_Info.csv" $logfile = $path + "a\$logdate.logfile.txt" $scriptrunrime = $path + "a\scripttime.txt" $ADServer = 'noc' $GetAdminact = Get-Credential Import-Module ActiveDirectory Function Update-ADUsers { $Users = Import-Csv -Path $csvfile $OU = 'ou=smite,ou=dota2,dc=depresion,dc=com','ou=lol,ou=lil,dc=depresion,dc=com' ForEach ($User In $Users) { $Description = $User."Descripcion" $Sam = $User."Logon Name" If ($Sam -And $Description) { $OU | Foreach { $UserInAD = Get-ADUser -Server $ADServer -Credential $GetAdminact -LDAPFilter "(sAMAccountName=$Sam)" -Searchbase $_ -SearchScope OneLevel If ( $UserInAD ) { Set-ADUser -Server $ADServer -Credential $GetAdminact -Identity $Sam -Replace @{Description = $Description} } #If Else { $sam + " Not modified because it doese not exist in AD or LogOn name field is empty on excel file" | Out-File $logfile -Append } } #Foreach } } } Update-ADUsers $endDTM = (Get-Date) "Elapsed Time: $(($endDTM-$startDTM).totalseconds) seconds""Elapsed Time: $(($endDTM-$startDTM).totalminutes) minutes"
I get this error:
Get-ADUser : No se encuentra el objeto de directorio En C:\a\2053.ps1: 44 Carácter: 34 + $OU | Foreach { $UserInAD = Get-ADUser -Server $ADServer -Credential $GetA ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (:) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.Activ eDirectory.Management.Commands.GetADUser
How can I solve it? Thanks.