Community

Subscribe
Highlighted

WFA Query AD

Using the following statement

$aduser = "Get-ADUser -f {SamAccountName -eq $user} -Properties mail | select-Object mail"

Get-WFALogger -Info -message $aduser  ONLY returns the  "Get-ADUser -f {SamAccountName -eq $user} -Properties mail | select-Object mail"

Has anyone been able to get the return and assign it to a variable to work with in WFA?

THanks!!!!

Re: WFA Query AD

If you want the value of the attribute mail for the user, the below statement will work.

$aduser = Get-ADUser -Filter {samAccountName -eq $user} -Properties mail |Select-Object "mail"

Get-WFALogger -Info -message $aduser.mail

--------

Your statement as below doesn't work, because you have declared it as a string. This has nothing to do with WFA, it will show similar result if executed with write-host on a powershell console.

$aduser = "Get-ADUser -f {SamAccountName -eq $user} -Properties mail | select-Object mail"

Write-Host $aduser

sinhaa

Re: WFA Query AD

Do you have a sample ?

Thank You,

John Marotta

USAA, Storage Management

913-2596

Re: WFA Query AD

here is what got:

PS Y:\> $aduser = "Get-ADUser -f {SamAccountName -eq '12345'} -Properties mail | select-Object mail"

PS Y:\> Write-Host $aduser

Get-ADUser -f {SamAccountName -eq '12345'} -Properties mail | select-Object mail

Re: WFA Query AD

just echos back the cmd but $aduser does not contain the data from the cmd.

Re: WFA Query AD

Of course, because you are trying the wrong command. I gave you the right one above ( in Green color ). Try that, it will work.

In powershell, anything withing double quotes will be treated as plain strings.

sinhaa

Re: WFA Query AD

Thanks sinhaa, I tried the one you provided in WFA but got this:

$aduser = Get-ADUser -Filter {samAccountName -eq $user} -Properties mail |Select-Object "mail"

Get-WFALogger -Info -message $aduser.mail

The term 'Get-ADUser' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

This exact cmd does work within powershell and returns the email from the $user:

$aduser = Get-ADUser -Filter {samAccountName -eq $user} -Properties mail |Select-Object mail

Thank You,

John Marotta

USAA, Storage Management

913-2596

Re: WFA Query AD

You need to Import the ActiveDirectory Module in your WFA command. Since it worked from PS console I assume you have ActiveDirectory PS modules available. Also since its on localhost, you don't need provide credentials.

Type the below in WFA command code to import the Module :

###

Import-Module ActiveDirectory

$aduser = Get-ADUser -Filter {samAccountName -eq $user} -Properties mail |Select-Object "mail"

Get-WFALogger -Info -message $aduser.mail

---

sinhaa

Re: WFA Query AD

Ok thanks again, tried

Import-Module ActiveDirectory

$aduser = Get-ADUser -Filter {samAccountName -eq $user} -Properties mail |Select-Object "mail"

Get-WFALogger -Info -message $aduser.mail

But got this:

Cannot bind argument to parameter 'message' because it is null.

Thank You,

John Marotta

USAA, Storage Management

913-2596

Re: WFA Query AD

You got this because the $user you have provided has empty mail Attribute and hence the $aduser.mail is null. Does the user you have given has this attribute set? By default mail attributes are NOT set for AD users. To verify, On PS console print like: write-host $aduser.mail