Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Null valued expression

$
0
0

You’ve piped the result of $searcher.FindOne() to “Select -ExpandProperty Properties”, but then tried to access $User.Properties.Item() on the next line. $User.Item() would probably work, assuming that FindOne() returned an object.

In any case, that seems like wasted effort. You’re already calling Get-ADUser, so you could just grab all the properties you need from there. Something like this:

$selectProperties = @(
    @{ Name = 'Name';      Expression = { $_.SamAccountName } }
    @{ Name = 'DN';        Expression = { $_.DistinguishedName } }
    @{ Name = 'LastLogon'; Expression = { $_.LastLogonDate } }
    @{ Name = 'FirstName'; Expression = { $_.GivenName } }
    @{ Name = 'LastName';  Expression = { $_.Surname } }
    @{ Name = 'Telephone'; Expression = { $_.OfficePhone } }
    @{ Name = 'Office';    Expression = { $_.physicalDeliveryOfficeName } }
)

Search-ADAccount -LockedOut -ResultPageSize 500 -UsersOnly |
Get-ADUser -Properties LastLogonDate, OfficePhone, physicalDeliveryOfficeName |
Select-Object -Property $selectProperties

Viewing all articles
Browse latest Browse all 13067

Trending Articles