Function not working

Welcome Forums General PowerShell Q&A Function not working

Viewing 1 reply thread
  • Author
    Posts
    • #237472
      Participant
      Topics: 9
      Replies: 21
      Points: 140
      Rank: Participant

      Hi everyone,

      I’m working on a function that assigns an Intune license to anyone within an Azure AD group that also has an E3 license. I enter my group parameter and thought I never get an error message, the licenses do not get applied either. Any assistance is greatly appreciated. Here is what I have. Thank you -Nelson

      function Add-AIMIntuneLicense {
      
         [CmdletBinding()] param (
      
            [Parameter(Mandatory=$True)]
      
            
      
      $Group)
      
      $Group | foreach-object { 
      
         if ( $_.SKUID -eq '6fd2c87f-b296-42f0-b197-1e91e994b900'){
      
         Set-AzureADUserLicense -ObjectId $_.UserPrincipalName -AssignedLicenses $licenses -Verbose } 
      
      }
      
      #Azure AD Groups
      
      $azbnmfa = Get-AzureADGroupMember -ObjectId 45e79d49-f4ab-4398-a817-4fac1af21810
      
      $azcemfa = Get-AzureADGroupMember -ObjectId eb201e30-f0c9-4f41-bbbd-bee66c9cc7b7
      
      $azideamfa = Get-AzureADGroupMember -ObjectId c1342d2d-294f-4adb-95d3-fcedfa2f2224
      
      $azahmfa = Get-AzureADGroupMember -ObjectId f2a58fba-8a48-4381-a668-db40f3425611
      
      $azmarmfa = Get-AzureADGroupMember -ObjectId 943fdf0c-2a07-4f5e-80ce-c2fb3b78e116
      
      $azeqmfa = Get-AzureADGroupMember -ObjectId eb998a5f-b91d-41b0-adc3-96286e6680de
      
      $azboucorpmfa = Get-AzureADGroupMember -ObjectId 530db391-9cf4-4d93-b2b5-68ecc7f0c8a7
      
      $azaimfitmfa = Get-AzureADGroupMember -ObjectId 45398851-131a-4a3d-a20d-8a58fb3495e2
      
      $azbouncoprmfa = Get-AzureADGroupMember -ObjectId c198997a-d539-4eef-9d08-f4d3047cef3f
      
      #Query of users with an E3 license
      
      #$azahe3mfa = $azahmfa | Select-Object UserPrincipalName -ExpandProperty AssignedLicenses | Where-Object {$_.SKUID -eq '6fd2c87f-b296-42f0-b197-1e91e994b900'} | Select-Object UserPrincipalName        
      
      #Custom Objects
      
      $license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
      
      $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
      
      #Intune SKU ID
      
      $license.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "EMS" -EQ).SkuID
      
      # Set the Intune license as the license we want to add in the $licenses object
      
      $licenses.AddLicenses = $license
      
      }
    • #237583
      Participant
      Topics: 12
      Replies: 1651
      Points: 2,702
      Helping Hand
      Rank: Community Hero

      The logic needs some work. What exactly are you passing as $Group? It appears to be an group object and could be an array of items as you are looping and looking at a property of the group. If you are passing the group to the function, then why are you manually defining groups in the function? Normally, you would pass a name or objectId to the function and lookup the group based on the passed information rather than statically defining groups.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.