Search code examples
powershellmicrosoft-graph-apihashtable

InputObject Properties Creation


I need some assistance creating a hashtable of users to use with Get-MGBetaUser

On the Microsoft Website (https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.users/get-mguser?view=graph-powershell-1.0) They will give you the parameter it's looking for (UserID) but I can't find any other articles online with exact use case such as this.

Currently I can get one object in the hash and have to access it directly by asking for the Index

    $Users['UserID'] = @{
    UserID = "<IDOfUser>"
    }

Get-MGBetaUser -InputObject $Users.UserID

If I pipe this same hash into Get-MGBetaUser, i'll get the error

Line |
   6 |  $Users | Get-MGBetaUser
     |  ~~~~~~~~~~~~~~~~~~~~~~~
     | Resource 'System.Collections.Hashtable' does not exist or one of its queried reference-property objects
     | are not present.

InputObject

The hash will have approx. 15-20k userids which will need to be added, and they'll be coming from a CSV

It looks like Microsoft will only accept the Pipeline input through this method with the hash. Everything else I've always done will allow piping an array of IDs into it.

Thank you in advance for any assistance


Solution

  • Thanks all for your responses, as it seems the answer is you couldn't supply the Graph SDK with an array or hash of users as originally intended, I opted to go a different route. The example I was giving was to have x number of jobs spin off based off the number of hashes/files I had, so that I could limit each jobs scope and create realistic timeframes for data pulls.

    I decided to create an hash table of Filters which will limit each jobs exposure. In my case, we have 140k+ students, so I created a filter for each SurNames ending in A,B,C... Spinning these into 27 jobs A-Z I can get complete results back within 30 minutes. In my testing, trying to do one big pull of students took hours. The reason for doing this is I am also opting to get Licensing information along with Sign In Activity (Which requires you to supply a GUID if you used a for-each)

    Allowing Graph to use the filter enables the SDK to get the data in batches, and not the other way around.

    If anyone has further insight into this, or sees a better way (Other than For-Each) feel free to let me know, otherwise I'm marking this closed!