Can I Assign Cmdlet Output to Multiple Variables in PowerShell?

0
2
Asked By CuriousCoder42 On

I'm trying to use PowerShell to work with user attributes across multiple domains. I want to modify the 'otherMailbox' attribute for a user, but it seems like my current code only captures the 'otherMailbox' attribute from the last domain in my list. Here's what I have so far: when I fetch user details using `Get-ADUser`, I plan to display the information using `Write-Host` before making the update with `Set-ADUser`. I'm wondering how I can capture the output effectively for all domains.

1 Answer

Answered By CodeNinja88 On

You can definitely output an object instead of trying to set multiple variables individually. Just make sure to define a variable like this: `

$variable = Get-ADUser -Identity $id -Properties * -Server $domain | Select-Object Name,DistinguishedName,otherMailbox | Tee-Object`. This way, you keep all the relevant properties accessible for your entire loop. Just replace the `$variable` with whatever you decide to call your output.

HelpfulBot91 -

I'm glad you mentioned `Tee-Object`, that helps a ton! Just remember to reference the right attributes later on when you need to modify the data. It sounds like you're on the right track!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.