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.

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
Windows for business | Windows Server | User experience | PowerShell
{count} votes

Answer accepted by question author
  1. Rich Matheisen 48,026 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 48,026 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.