# xGroup behavior

**URL:** <https://forums.powershell.org/t/xgroup-behavior/3309>\
**Category:** DSC\
**Created:** [October 23, 2014, 3:52am UTC](https://forums.powershell.org/t/xgroup-behavior/3309 "2014-10-23T03:52:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael-felkins](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@michael-felkins](https://forums.powershell.org/u/michael-felkins)\
**Post date:** [October 23, 2014, 3:52am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/1 "2014-10-23T03:52:11Z")

</div>

I am using xGroup because I have to add members to the local group that are in a different, trusted domain.  
If I use the property Members I get an error:

[xGroup]Performance\_Log\_Users  
D:\Scripts\iAPPWebRole.ps1::358::3::xGroup  
The PowerShell provider MSFT\_xGroupResource threw one or more non-terminating errors while running the Test-TargetResource functionality.  
These errors are logged to the ETW channel called Microsoft-Windows-DSC/Operational. Refer to this channel for more details.

If I use MembersToInclude with the same members, everything works fine.

Perhaps I am missing something here or there is a bug.

I also notice that the first time through a new configuration xGroup errors complaining that there is no such object as the Group I am trying to create. If I run it again or create the groups manually before I run my script, everything works as long as I use MembersToInclude.

xGroup xx\_rsc\_fs\_sitecore\_ro {  
GroupName = “xx\_rsc\_fs\_sitecore\_ro”  
Ensure = “Present”  
Description = “xx\_rsc\_fs\_sitecore\_ro”  
MembersToInclude = @(“Trusted\Dept\_IT Dev”)  
Credential = $cred  
}

puzzled OldDog

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [October 30, 2014, 9:17am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/2 "2014-10-30T09:17:22Z")

</div>

It’s very likely just a bug of some kind. Do we have a community version of that resource in the GitHub repo, from our DSC Hub page?

---

<div class="post-metadata">

**Author:** ![simon-wahlin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/simon-wahlin/32/407_2.png) [@simon-wahlin](https://forums.powershell.org/u/simon-wahlin)\
**Post date:** [October 31, 2014, 12:59pm UTC](https://forums.powershell.org/t/xgroup-behavior/3309/3 "2014-10-31T12:59:35Z")

</div>

There isn’t a community version yet but I took the liberty to fork the cPSDesiredStateConfiguration and add the cGroup resource.

I’ve fixed the bug causing errors when a group is created but I wasn’t able to reproduce the problem using Members. This is how I wrote the configuration:

```
cGroup MyGroup
{
    Ensure = 'Present'
    GroupName = 'MyGroup'
    Members = 'Test1','Test2'
}
```

My fork is available here:  
[https://github.com/SimonWahlin/cPSDesiredStateConfiguration](https://github.com/SimonWahlin/cPSDesiredStateConfiguration)

I’ll give it some more testing and then I’ll submit a pullrequest.

---

<div class="post-metadata">

**Author:** ![michael-felkins](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@michael-felkins](https://forums.powershell.org/u/michael-felkins)\
**Post date:** [November 11, 2014, 4:17am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/4 "2014-11-11T04:17:18Z")

</div>

Hi,

I tried your cGroup, but got the same result. I compared it to the xGroup and I could find no changes. Did I grab the wrong code?

Old Dog

---

<div class="post-metadata">

**Author:** ![simon-wahlin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/simon-wahlin/32/407_2.png) [@simon-wahlin](https://forums.powershell.org/u/simon-wahlin)\
**Post date:** [November 11, 2014, 4:59am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/5 "2014-11-11T04:59:34Z")

</div>

The only change is that cGroup checks if $Group -ne $null on row 169.

If xGroup is used to manage a Group that doesnt exist the search on row 168 results in $Group being set to $null.

```
$group = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($localPrincipalContext, $GroupName);
```

On the next row (169), $Group is added to $Disposables.

Later on when each item in $Disposables are disposed (row 436), the null value will result in an error stating “You cannot call a method on a null-valued expression.”

The cGroup resource checks if $Group -ne $null Before adding it to $disposables.

This change should fix the errors generated the first time a configuration runs (when the Group is created).

Regarding your problem with using Members vs MembersToInclude I could not test the scenario since I do not have a trusted domain in my lab.

---

<div class="post-metadata">

**Author:** ![craig](https://avatars.discourse-cdn.com/v4/letter/c/ed8c4c/32.png) [@craig](https://forums.powershell.org/u/craig)\
**Post date:** [November 13, 2014, 8:12am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/6 "2014-11-13T08:12:04Z")

</div>

I’ve got a problem adding a domain user to a local group, the error is “Network Path Not Found” and happens for a short time after the computer joins the domain, but works sometime afterwards.

Still narrowing it down, but grabbing a coffee then rebooting the computer works for now.

---

<div class="post-metadata">

**Author:** ![michael-felkins](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@michael-felkins](https://forums.powershell.org/u/michael-felkins)\
**Post date:** [November 21, 2014, 11:25am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/7 "2014-11-21T11:25:25Z")

</div>

Ok, I was really happy that the xGroup started working with the fix to line 170.

if($group -ne $null)  
{  
$disposables.Add($group) | out-null  
}

Now its doing the same thing, except !!! it only does it when I try to add members.  
Either by members or memberstoadd.

xGroup wm\_rsc\_shr\_webimport\_full {  
GroupName = “wm\_rsc\_shr\_webimport\_full”  
Ensure = “Present”  
Description = “wm\_rsc\_shr\_webimport\_full”  
MembersToInclude = “trusted\production admins”  
Credential = $cred  
}

I also tried it with @( “trusted\production admins”) both with members and MembersToInclude

Here is what I get:

VERBOSE: [FPKDSCSCRUBBER1]: LCM: [Start Test] [[xGroup]wm\_rsc\_shr\_webimport\_full]  
VERBOSE: [FPKDSCSCRUBBER1]: [[xGroup]wm\_rsc\_shr\_webimport\_full] A group with the name  
wm\_rsc\_shr\_webimport\_full exists.  
You cannot call a method on a null-valued expression.  
+ CategoryInfo : InvalidOperation: (🙂 , CimException  
+ FullyQualifiedErrorId : InvokeMethodOnNull  
+ PSComputerName : FPKDSCSCRUBBER1

If I comment out the Members line it goes through with out an error.

Puzzled OldDog

---

<div class="post-metadata">

**Author:** ![michael-felkins](https://avatars.discourse-cdn.com/v4/letter/m/a9adbd/32.png) [@michael-felkins](https://forums.powershell.org/u/michael-felkins)\
**Post date:** [November 24, 2014, 6:30am UTC](https://forums.powershell.org/t/xgroup-behavior/3309/8 "2014-11-24T06:30:05Z")

</div>

Found the problem. It did not like the credentials I was providing.  
Yet another informative error message.

OldDog

---

<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, 9:17pm UTC](https://forums.powershell.org/t/xgroup-behavior/3309/9 "2024-05-16T21:17:26Z")

</div>

Closed on May 16, 2024, 9:17pm UTC


