title: Azure Powershell - Add User to Group, filtered by license
body: <p>Been trying to create a Powershell script to achieve the following.</p>
  <ol>
  <li>Check which users have a specific license assigned</li>
  <li>assign these users to a specific security group.</li>
  </ol>
  <p><code>Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match &quot;DEVELOPERPACK_E5&quot;} | Add-AzureADGroupMember -ObjectID c1ec272d-e0d2-496c-ba65-602e7d822c75</code></p>
  <p>The first part of the script runs okay <code>Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match &quot;DEVELOPERPACK_E5&quot;}</code> which returns the users that have the license, however when trying to pipe results to &quot;AddAzureADGroupMember&quot; an error occurs.`</p>
  <p>Error:</p>
  <pre><code>At line:1 char:1
  + Get-MsolUser | Where-Object {($_.licenses).AccountSkuId -match &quot;DEVEL ...
  + ~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (Microsoft.Onlin...omation.GetUser:GetUser) [Get-MsolUser], PipelineStoppedException
      + FullyQualifiedErrorId : System.Management.Automation.PipelineStoppedException: The pipeline has been stopped.
     at System.Management.Automation.CommandProcessor.ProcessRecord()
     at System.Management.Automation.CommandProcessorBase.DoExecute()
     at System.Management.Automation.Internal.Pipe.AddToPipe(Object obj)
     at System.Management.Automation.Internal.Pipe.AddItems(Object objects)
     at System.Security.SecurityContext.Run(SecurityContext securityContext, ContextCallback callback, Object state)
     at System.Management.Automation.MshCommandRuntime.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
     at System.Management.Automation.Cmdlet.WriteObject(Object sendToPipeline, Boolean enumerateCollection)
         at Microsoft.Online.Administration.Automation.MsolCmdlet.ProcessList(SearchDefinition searchDefinition, Int32 maxResultsSize) in X:\bt\1067178\repo\src\dev\PowerShell.V1\modules\psmodule\Cmdlets\MsolCmdlet.cs:line 372,Microsoft.Online.Administration.Automation.G
     etUser
  
  Add-AzureADGroupMember : Error occurred while executing AddGroupMember
  Code: Request_BadRequest
  Message: Invalid object identifier 'Microsoft.Online.Administration.User'.
  RequestId: be0ee2c5-44e0-41f3-a9e2-f8396980cf6b
  DateTimeStamp: Fri, 22 Oct 2021 10:37:21 GMT
  HttpStatusCode: BadRequest
  HttpStatusDescription: Bad Request
  HttpResponseStatus: Completed
  At line:1 char:86
  + ... PACK_E5&quot;} | Add-AzureADGroupMember -ObjectId c1ec272d-e0d2-496c-ba65- ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : NotSpecified: (:) [Add-AzureADGroupMember], ApiException
      + FullyQualifiedErrorId : Microsoft.Open.AzureAD16.Client.ApiException,Microsoft.Open.AzureAD16.PowerShell.AddGroupMember```
  </code></pre>