# Function not working

**URL:** <https://forums.powershell.org/t/function-not-working/14579>\
**Category:** PowerShell Help\
**Created:** [June 22, 2020, 2:43pm UTC](https://forums.powershell.org/t/function-not-working/14579 "2020-06-22T14:43:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nelsonsaenz](https://avatars.discourse-cdn.com/v4/letter/n/7ab992/32.png) [@nelsonsaenz](https://forums.powershell.org/u/nelsonsaenz)\
**Post date:** [June 22, 2020, 2:43pm UTC](https://forums.powershell.org/t/function-not-working/14579/1 "2020-06-22T14:43:02Z")

</div>

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

}
```

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [June 23, 2020, 4:13am UTC](https://forums.powershell.org/t/function-not-working/14579/2 "2020-06-23T04:13:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/function-not-working/14579/3 "2024-05-16T20:29:18Z")

</div>


