0

This could be a dumb question but nevertheless I am struggling to find the relevant information for this online and intellisense can only offer so much.

Below is some code I have quickly produced:

$upn = Get-Mailbox | Select-Object {$_.Alias}
$string = ":\Calendar"

foreach($_ in $upn)
{

$alias = $_

$Buffer = @();
$Buffer += '{0}' -f $alias;

Write-Host $Buffer
}

The results from the buffer output are as follows:

@{Alias=Test00}
@{Alias=Test01}
@{Alias=Test02}
@{Alias=Test03}
@{Alias=Test04}

When in fact, I want it to output like follows:

Test00
Test01
Test02
Test03
Test04

In all honesty I have had this occur to me in the past but wrote alternative solutions to work around it. I have come to the realization I can't and so I need to learn this and find out why the output displays @{} ?

I have tried selecting the column header by Name rather than the variable (Alias instead of {$_.Alias})

Also tried printing out the variable $_ and these results are identical to putting the variables into a formatted array.

Where am I going wrong?

unkn0wn
  • 59
  • 2
  • 6
  • 1
    `$upn = Get-Mailbox | Select-Object -expand {$_.Alias}` – Matt Feb 09 '16 at 16:32
  • You have an object array with an alias property. Using `-ExpandProperty` with `select-object` or just `(Get-Mailbox).Alias` should get you what you want. – Matt Feb 09 '16 at 16:34
  • @Matt Thanks a bunch, Matt! I can't one up your answer since it's a comment but your prompt response is appreciated highly. So if I am correct in saying this, certain clauses results can be in array even if it is non user-declared? (evidently here, I am just trying to put it into words) – unkn0wn Feb 09 '16 at 16:51
  • Also, `foreach($alias in $upn){}` will suffice, no need to superfluously overwrite `$_` – Mathias R. Jessen Feb 09 '16 at 16:52
  • @KieranGroome PowerShell is very type friendly. Experiment with `Get-Member` and `$variable.GetType().FullName` to see results. – Matt Feb 09 '16 at 17:04

0 Answers0