# Add AD group member Credential

**URL:** <https://forums.powershell.org/t/add-ad-group-member-credential/20839>\
**Category:** PowerShell Help\
**Created:** [November 4, 2022, 2:50pm UTC](https://forums.powershell.org/t/add-ad-group-member-credential/20839 "2022-11-04T14:50:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinod-kumar](https://avatars.discourse-cdn.com/v4/letter/v/a87d85/32.png) [@vinod-kumar](https://forums.powershell.org/u/vinod-kumar)\
**Post date:** [November 4, 2022, 2:50pm UTC](https://forums.powershell.org/t/add-ad-group-member-credential/20839/1 "2022-11-04T14:50:12Z")

</div>

Hello - I am trying to add devices to the AD group using different credentials other than logged on.

$devName = “Device01”  
$myUser = “contoso\_serviceA”  
$userPassword = ConvertTo-SecureString “Password1” -AsPlainText -Force  
$mycred = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList “$myUser”, “$userPassword”  
Add-ADGroupMember -Identity “PLB” -Members $devName -Server “[ABCD.contoso.com](http://ABCD.contoso.com)” -Credential $mycred -ErrorAction Stop

Failed to add Device01$ to the group due to error Cannot process argument transformation on parameter ‘Credential’. Access is denied

Verified the user contoso\_serviceA has write permission to the group to add members.

Anything else?

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [November 4, 2022, 9:55pm UTC](https://forums.powershell.org/t/add-ad-group-member-credential/20839/2 "2022-11-04T21:55:46Z")

</div>

Hi, welcome back 👋

Firstly, when posting code in the forum, please can you use the preformatted text \</\> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

[How to format code on PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif)

Now, talking of quote marks, when you put them around `$userPassword` you’re passing that parameter as a `String` to the constructor instead of the `SecureString` that it’s expecting:

```auto
PS E:\Temp> "$pass".GetType().Name
String
PS E:\Temp> $pass.GetType().Name
SecureString

```

To resolve this, you guessed it, don’t wrap it in quote marks. In fact, you can drop them from `$myuser` as well:

```auto
$mycred = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList $myUser, $userPassword

```

In fact, you don’t even need the `-ArgumentList` parameter:

```auto
$mycred = New-Object -TypeName System.Management.Automation.PsCredential ($myUser, $userPassword)

```

---

<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:16pm UTC](https://forums.powershell.org/t/add-ad-group-member-credential/20839/3 "2024-05-16T20:16:23Z")

</div>


