Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Using the "Endswith" Method with Get-ADUser

$
0
0

I am using get-ADuser to return several properties one of which has multiple values. I am using the "Endswith" method to sort the values I want from the ones I dont. However, I am not sure how to proceed after I get my boolean values returned. I only want the value if it is equal to true.

Here is the code I am have so far:

$working = Get-ADUser -Filter {proxyAddresses -like "*test.user@ABC.123.com"} -Properties proxyAddresses

#Returns boolean

$Working1 = $working.proxyAddresses.endswith("@ABC.123.com")

PS C:\$working1

False

False

True

That is where I am stuck. The following line of code is what I tried next:

$working1 | % ($_. -eq $True) {Out-Host}Else{$Null}

However that returns an error:

% : Input name "False" cannot be resolved to a method.

At line:1 char:13

+ $working1 | % ($_ -eq $True) {Out-Host}Else{$Null}

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : InvalidArgument: (False:PSObject) [ForEach-Object], PSArgumentException

+ FullyQualifiedErrorId : MethodNotFound,Microsoft.PowerShell.Commands.ForEachObjectCommand

I have a feeling I am going about the last line of code entirely wrong. I can see that $Working1 contains boolean values, I am not sure how to tie it back and retrieve the corresponding values for "True" from $working. Any help is GREATLY appreciated!!

 


Viewing all articles
Browse latest Browse all 6937

Trending Articles