Brtrnd
Brtrnd

Reputation: 196

displaying information from two objects in powershell

I'd like to display information from skype and from AD next to eachother. (I'm asking this as a specific question, but I've stumbled against this more often).
the simplified version would be this:

get-csuser | ForEach-Object { $_.displayname,(Get-ADUser -Identity $_.samaccountname -Properties officephone).officephone  } | ft  

This would show me the displayname from skype and the phone number from AD. But it will show it as new rows, while I would like to have it in one handy table.
What's the best way to achieve this?
Thank you

Upvotes: 0

Views: 267

Answers (2)

zerocool18
zerocool18

Reputation: 523

I think you are looking for "calculated properties" in Select-Object. name is your label and expression is a script-block. Both are wrapped in a hash-table.

@{ Name = '';  Expression = {}}

So, for your code, it can be like this(didn't check for syntax) :

get-csuser | ForEach-Object { $_.displayname, @{ n= 'officePhone'; e = { (Get-ADUser -Identity $_.samaccountname -Properties officephone).officephone } } 

Note : we can use short-hands for name and expression.

Link : Further Examples

Upvotes: 2

Alex_P
Alex_P

Reputation: 2950

Maybe this helps you.

$list = foreach ($process in (Get-Process)) {
        [PSCustomObject]@{
            ProcessID = $process.Id
            Name = $process.Name
        }
    }

$list | Format-Table

Of course, you adjust the loop for the objects you enter the information you want to get, but generally this may help.

Upvotes: 1

Related Questions