Quantcast
Channel: Windows Server General Forum forum
Viewing all articles
Browse latest Browse all 24879

How to fix "Invalid Class" in Powershell

$
0
0

 - I am purging inactive userprofiles from 2012r2 RDS Collection host servers using powershell. 

 - Out of six servers, the command I'm using works on all but one.

 - All servers are Windows Server 2012r2 and have the exact same patching level, and are running Powershell 4.0

Here is the full syntax:    Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\')[-1] -eq 'USERPROFILE' } | Remove-CimInstance

Here is the resulting output: 

Get-CimInstance : Invalid class
At line:1 char:1
+ Get-CimInstance -Class Win32_UserProfile | Where-Object { $_.LocalPath.split('\' ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : MetadataError: (root\cimv2:Win32_UserProfile:String) [Get-CimInstance], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041010,Microsoft.Management.Infrastructure.CimCmdlets.GetCimInstanceCommand

NOTE:  If I just strip everything out and simply type "Get-CimInstance -Class Win32_UserProfile", I get the same error, so it's not the Object, it's the class.  

NOTE:  If I switch to Get-WMIObject, I get the same "Invalid Class" error, see below:

Get-WmiObject : Invalid class "Win32_Userprofile"
At line:1 char:1
+ Get-WmiObject Win32_Userprofile
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

___________________________________________________________________________________________

Here are my questions:

1.)  Has anyone seen this before, and if so, what did you do to resolve it?

2.)  Does anyone know if there is a way to rebuild/reinstall the WMI Classes?

3.)  As the same thing happens between Get-CimInstance and Get-WmiObject, can anyone point me toward what the underlying source/cause of the problem might be? 

I consider myself somewhat unskilled Powershell user, as I don't use it much.   Regardless, these commands work fine on 5 out of 6 other identical servers.  

Any help is appreciated!, thanks.

-sMh-



Viewing all articles
Browse latest Browse all 24879

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>