Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Trying to clear out an AD attibute with powershell

$
0
0

Hello.

I have made a litle script where i run commands against my AD. IT works greate, until i came to a litle problem where i want to clear out an attribute from the AD.

Have searched high and low, but havn't found anything that i can use directly.

Here is the code.

Function RaderaLogfilerUser
<#
  My comment on how the code should work, in forign language :D

#>
{
    param($company)
    $ObjFilter = "(&(objectCategory=person)(objectCategory=User))" 
    $objSearch = New-Object System.DirectoryServices.DirectorySearcher 
    $objSearch.PageSize = 500 
    $objSearch.Filter = $ObjFilter
    $objSearch.PropertiesToLoad.Add( "name" )
    $objSearch.PropertiesToLoad.Add( "info" )
    $objSearch.SearchRoot = "LDAP://OU=Domain Users,DC=company,DC=local" 
    $AllObj = $objSearch.FindAll()  
       foreach ($Obj in $AllObj) 
           {
            $objItemS = $Obj.Properties
            $user = [ADSI] [string]  $objItemS.adspath
            $time = get-date
            $user.psbase.invokeSet("info", "Clear the logfile: $time")
            $user.psbase.invokeSet("extensionAttribute1", "")

            $user.CommitChanges() 
          
 
 }}

The problem is that when i run the script with "", $null or clear() it fails with the following message

Exception calling "CommitChanges" with "0" argument(s): "The attribute syntax specified to the directory service is invalid.
"
At C:\Scripts\UpdateUsers.ps1:258 char:32
+             $user.CommitChanges <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

Am i missing some litle trick of how to clear the AD attribute within the same session. Have found some vbscript commands to clear out the attribute, but i don't want to mix the codes.. if possible.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>