header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Deleting Users Problem
Last Post 15 Jun 2010 08:56 AM by James. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
JamesUser is Offline
Basic Member
Basic Member
Posts:374
Avatar

--
15 Jun 2010 08:56 AM

    Hello,

    I have the following function:



    function Delete-ADUser { Param($userName = $(throw 'need username')) $searcher = New-Object System.DirectoryServices.DirectorySearcher([ADSI]"","(&(objectcategory=user)(sAMAccountName=$userName))") $user = $searcher.findone().GetDirectoryEntry() $user.psbase.DeleteTree() #$user.SetInfo() }



    I am running it as :



    $Global:SchoolList = Import-Csv "C:\Powershell\CSV\SchoolsList.csv"
    #Remove Disabled Users

    $SchoolList |
    ForEach-Object{ $School = $_.School $ou = 'OU=users,OU=' + $School + ',Rest of OU Structure here'
    Get-QADUser -Title "student", "teacher","staff","parent" -SearchRoot $OU -SizeLimit 0
    $SamAccountName = $_.SamAccountName
    Delete-ADUser $SamAccountName
    }



    Does anyone know why the following error is being produced:

    Exception calling "FindOne" with "0" argument(s): "The (&(objectcategory=user)(sAMAccountName=)) search filter is inval
    id."
    At C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:209 char:26
    + $user = $searcher.findone <<<< ().GetDirectoryEntry()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    You cannot call a method on a null-valued expression.
    At C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:210 char:24
    + $user.psbase.DeleteTree <<<< ()
        + CategoryInfo          : InvalidOperation: (DeleteTree:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    Exception calling "FindOne" with "0" argument(s): "The (&(objectcategory=user)(sAMAccountName=)) search filter is inval
    id."
    At C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:209 char:26
    + $user = $searcher.findone <<<< ().GetDirectoryEntry()
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    You cannot call a method on a null-valued expression.
    At C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:210 char:24
    + $user.psbase.DeleteTree <<<< ()
        + CategoryInfo          : InvalidOperation: (DeleteTree:String) [], RuntimeException
        + FullyQualifiedErrorId : InvokeMethodOnNull

    The line it refers to in the profile is the function above.

    If anyone has any ideas I would much appreciate them.

    Many Thanks

    James

    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer