CMDLETS available on Server 2012 (PS ver 4)

Hi all.

I’m trying to run some simple scripts against a bunch of older servers - 2012 R2 and even 2008 R2 (yes I know and we are working to get rid of them), but the commands fail.

For instance if I try to run:

Invoke-Command -ComputerName XXXXX -ScriptBlock{ Get-LocalGroupMember -Group “Administrators” }

I receive an error like: The term ‘Get-LocalGroupMember’ is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo : ObjectNotFound: (Get-LocalGroupMember:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : XXXXXX

I get the same error if I try to run Get-LocalGroupMember -Group “Administrators” from the PS console on the server.
The server has PS version 4 installed.

Are Get-LocalGroupMember not supported on 2012 R2?
It also fails on the 2008 R2 boxes but that I can understand, but does Server 2012 not have a “modern” version of powershell which supports such “basic” commands.
I cannot believe that Get-LocalGroupMember is a newer invention from Microsoft :slightly_smiling_face:

Thanks for any feedback!

It’s not just about the use PowerShell version. The underlying OS and dotNet-Framework influence the supported commands as well.
You should look for scripts supporting PS version 2.0 where Get-LocalGroup and LocalGroupMember didn’t exist yet.

1 Like

The local group cmdlets were introduced in Windows PowerShell 5.1.

Server 2012 R2 shipped with PowerShell 4.0 so unless you’ve installed Windows Management Framework 5.1 you won’t have the cmdlets.

WMF 5.1 requires .NET framework 4.5.2 so you may need to upgrade .NET as well.

Where upgrading is a problem, I usually go with net localgroup. There are other ways but the output from net localgroup is consistent and easy to parse.

1 Like

Thanks Matt!
Net Localgroup seems to work against the 2012 servers. Not the 2008 though.
I will see if we can get the servers upgraded. And else I’ll go with the Net command instead.

What’s your thoughts on upgrading the NET framework and powershell version on the 2008 servers? Will that be a suitable way to go in your opinion?

Do you really need this? I wouldn’t spend too much effort if you’re going to get rid of these servers soon anyway.

1 Like

For me it would depend on what they’re used for, how much effort it is to upgrade them, and how easily you can roll them back if something goes wrong.
Non-critical VMs that you can snapshot, install, and revert the snapshot if it goes wrong: I’d try to upgrade them.
Business critical, physical machines: I’d put my efforts into getting rid of them ASAP.

1 Like

You have a point.
However I’m not sure exactly when these servers will be replaced and we need to run scripts agains the servers.

These are all virtual machines and I see your points.
It’s not up to me to decide this.

Thanks for your thought on this guys. It was very helpful.


Have you tried using ADSI on the older boxes?

Here is a function I use. Not as robust but maybe worth a try. If you only want Administrators, you will need to tweek it as it enumerates all local groups.

Function Get-LocalGroupInfo {

	This function will enumerate local groups for systems with older PowerShell
	where Get-LocalGroup is not available


	$remoteHost = [ADSI]"WinNT://$System,computer"

	$localGroupInfo = @()

	$remoteHost.psbase.children | Where-Object { $_.psbase.schemaClassName -eq 'group' } | foreach {
   	 	$Group =[ADSI]$_.PsBase.Path
   	 	$Group.PsBase.Invoke("Members") | foreach {
			$User = $_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)
			$UserInfo = [PSCustomObject][Ordered] @{
				'Group' = [System.String]$Group.Name
				'Member' = $User
			$localGroupInfo += $UserInfo
	Return $localGroupInfo

Hey tonyd.

Thanks for the script.
I will definately try it out.