Add-LocalGroupMember is not recognized as a cmdlet , function , script or file on windows server 2012
Asked Answered
G

2

7

Is there a way to add addlocalgroupmember module on windows server 2012? I didnot find any. I need to add AD account on local admin group but i couldn't find a way.

The closest i was able to reach is to install activedirectory-powershell feature using the following command but that too didn't help.

Basically i need to find a way to run a powershell command similar to the below one on win server 2012 -

Add-LocalGroupMember -Group "Administrators" -Member "domain\user"
Grief answered 10/4, 2020 at 9:18 Comment(3)
according to the MSDocs page for that cmdlet, it REQUIRES at least ps5.1 ... and you don't have that installed, apparently.Sugary
for a workaround, look into the ADSI stuff - it provides a way to address the local accounts.Sugary
See: Add user to local groupCapp
H
8

You don't really need to complicate things much here. In reality you can achieve what you want with a one-line without installing any module since you're not modifying AD you can simply use.

net localgroup Administrators /add domain\username

Heriberto answered 10/4, 2020 at 12:13 Comment(2)
What if the requirement is to use PowerShell?Psychopathy
@Psychopathy Powershell can interpret most of cmd commands so you can run that in a powershell script or terminal and the result will be the same.Heriberto
L
2

You need to install the Windows Management Framework (WMF) v5.1 that can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=54616

After installing, you will can use the module Microsoft.PowerShell.LocalAccounts and the command Add-LocalGroupMember will work just fine.

Larch answered 2/3, 2021 at 14:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.