header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Deleting Users Problem
Last Post 15 Jun 2010 04:56 PM by morpheus83uk. 0 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
morpheus83ukUser is Offline
Basic Member
Basic Member
Posts:295
Avatar

--
15 Jun 2010 04:56 PM  

Hello,

I have the following function:

<BR><BR>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() }<BR><BR>


I am running it as :

<BR><BR>$Global:SchoolList = Import-Csv "C:\Powershell\CSV\SchoolsList.csv" <BR>#Remove Disabled Users <BR><BR>$SchoolList | <BR>ForEach-Object{ $School = $_.School $ou = 'OU=users,OU=' + $School + ',Rest of OU Structure here' <BR>Get-QADUser -Title "student", "teacher","staff","parent" -SearchRoot $OU -SizeLimit 0 <BR>$SamAccountName = $_.SamAccountName <BR>Delete-ADUser $SamAccountName <BR>}<BR><BR>


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.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer