Array related question


Newish to Powershell so pardon anything that isn’t worded just right.

I’m running a powershell script against o365 and trying to switch the way it is done but the arrays seem to produce different outputs.

Running this returns all email address for users in our tenant and loads them into $the.

$the = Get-Recipient -ResultSize unlimited | select emailaddresses

If I do $the.emailaddresses it will split each emailaddress and display it 1 per line.

Due to the volume of items returned this command seems to return inconsistent results.

So I switched it up to the command below, which works fine and produces a text file.

Invoke-Command -Session(Get-PSSession) -scriptblock {Get-Recipient -ResultSize unlimited | Select-Object emailaddresses } | select emailaddresses | out-file -Append .\rawlog.txt

If I then run the command below I get the contents of the text file in a variable

$the1 = Get-Content .\rawlog.txt

If I view the contents of $the or $the1 in the console they appear to be the same data and look the same. Though I am unable to enter $the1.emailaddresses, it does not work and I get $null output. I’ve also noticed that $the.getvalue(3) returns the header (Emailaddresses) and the data that is in line 3 but does not count the header lines.

{smtp:xxxxx@Nxxxxx, smtp:xxxxx@xxxx, smtp:xxxx@jxxxx, smtp:xxxxx@xxxx…}

Where $the1.getvalue(3) returns the data in line 3 but includes the header lines countable lines.

{smtp:yyyyyy@Nyyyyy, smtp:yyyy@yyyyy, smtp:yyyyy@jyyyyy, smtp:yyyyyy@yyyy…}

Hopefully that makes sense.

Either way I am missing some piece of information about the array and the data contained within it. If I can provide further information let me know.


Why do you think that and what did you try to confirm your guess?

And finally: what’s the question? What do you want to do actually?

I don’t have an environment to test at the moment … your first command creates an array of objects and you can access single object or attributes of objects with the “dot - notation” you used. To export this to a plain text file might not be the best idea - it depends on the purpose. :wink:

If the request returns all results it returns over 400K items. Some days I’ll get 100K back others I’ll get 300K. Each time the script runs it issues a fresh login with a new session. It generally runs in under an hour.

The purpose is to audit the email addresses a user has against what they should have. We have 60K-70K accounts. Running a command against o365 for each account and evaluating at that point takes 24 hours and is not feasible. So, I’m exporting all the addresses, loading them into a hash of array and then searching against that to make it run in a decent amount of time.

Ultimately, it would be great to get a consistent export from o365 :), not one that works fine one day and doesn’t the next. Again, I’m relatively new to this so am open to suggestions if anyone has them,for a better way to do this.