Link to home
Start Free TrialLog in
Avatar of mrfite
mrfiteFlag for United States of America

asked on

Add a variable to property in Powershell

Good Day,

This should be very quick and easy.

I have a powershell script and we have multiple child domains.  I would like to include a new property for which domain the ADUser object is in as part of the output.

Below is my script:
__________________________________________________________
$z='y'
$domains = (Get-ADForest).Domains

While ($z -eq 'y')
    {
    $userx = @()
    $nameregex = Read-Host "put in part or al of a user's name"
    $userd = '*'+$nameregex+'*'
        foreach ($domain in $domains) {
            if ($domain -ne "cst.is.local" ) {
                Write-Output "Searching Domain " $domain
               $userx += Get-ADUser -Filter {name -like $userd} -server $domain | Select-Object name,samaccountname,enabled,DistinguishedName
             }
        }
        Write-output $userx | ft -AutoSize
    $z = Read-Host 'do you want to find another user?'
    $z = $z.ToLower()
    }

________________________________________________________________
The script works great but I would like to add the $domain variable to the Select-object output.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrfite

ASKER

Thanks,

I knew it was something simple.
Avatar of mrfite

ASKER

Thanks again