Cannot validate argument on parameter 'Identity'.

Gilberto De Campos 20 Reputation points
2024-02-29T20:01:16.2766667+00:00

At:

$Users = Get-ADUser -filter * -Properties Manager | Where-Object { $_.Enabled -Match "false"} $Manager When manager is empty, how can we avoid: Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,432 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,457 questions
{count} votes

Accepted answer
  1. Rich Matheisen 46,551 Reputation points
    2024-03-02T15:37:13.06+00:00

    If you want all disabled users, regardless of the presence of an assigned manager, then try this code:

    $Users = Get-ADUser -filter "enabled -eq 'false'" -Properties Manager | 
            ForEach-Object{
                    if ($manager){
                            Select-Object Name,samAccountName, @{n="ManagerName";e={(get-aduser $_.manager).samaccountname}}
                    else{
                            [PSCustomObject]@{
                                    Name = $_.Name
                                    samAccountName = $_.samAccountName
                                    ManagerName = "No manager assigned to this user"
                            }
                    }
            }
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 46,551 Reputation points
    2024-02-29T20:39:49.0866667+00:00

    Your code doesn't make sense. You haven't declared $Manager to be a variable. Did you mean something like this:

    $Users = Get-ADUser -filter "enabled -eq 'false' -and manager -like '*'" -Properties Manager | 
            Select-Object Name,samAccountName, @{n="ManagerName";e={(get-aduser $_.manager).samaccountname}
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.