# Get-ADuser in a function

**URL:** <https://forums.powershell.org/t/get-aduser-in-a-function/1246>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/get-aduser-in-a-function/1246 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/get-aduser-in-a-function/1246/1 "2011-12-31T18:30:00Z")

</div>

by dafinch at 2012-10-17 04:46:34

> I’m fairly new to powershell and i’m trying to learn how to put together a function with parameters. The parameters seem to be working correctly but i’m having an issue with the actual Get-ADuser. If I try my example below the Get-ADuser works outside of the function but it doesnt inside the function. I’ve verified that the $ADGroupName contains the name of the group i’m passing into the function. But the get-adgroup inside the function returns nothing.   
>   
> I’ve got powershell v3 installed. Any help on this would be appreciated.   
>   
>   
> `Import-Module activedirectoryFunction Show-GroupMembers {	Param( [Parameter(Mandatory=$True)] [string]$ADGroupName	)	$ADGroupName	get-adgroup -filter {name -like $ADGroupName}}$ADGroupName = "testgroup"Show-GroupMembers $ADGroupNameget-adgroup -filter {name -like $ADGroupName}#^–this works`

by DonJ at 2012-10-17 08:23:55

> Couple things. If you’re going to use [Parameter()], add [CmdletBinding()] prior to your Param block:  
>   
> `[CmdletBinding()]Param()`  
>   
> Your other problem is that you’ve declared $ADGroupName as an array; the -filter parameter doesn’t want an array. You can’t use -like against an array, either. Inside your function, you’d need to enumerate through that array and deal with just one array item at a time.

by dafinch at 2012-10-17 09:51:45

> Thanks! That fixed it. Once I put my Get-ADGroup in a foreach it worked perfectly.  
>   
> Thanks again

---

<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:58pm UTC](https://forums.powershell.org/t/get-aduser-in-a-function/1246/2 "2024-05-16T20:58:13Z")

</div>

Closed on May 16, 2024, 8:58pm UTC


