mrfite
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,enable d,Distingu ishedName
}
}
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.
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,enable
}
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again
ASKER
I knew it was something simple.