Get-DSCResource Error

If I get an error mentioning v1.0 when running Get-DSCResource for the first time in PowerShell v4 (as shown below) can you tell me what I am doing wrong? (This is on x64 Windows 7 and I’m working through the DSC eBook.) Thanks.

PS C:\Program Files\WindowsPowerShell\modules> get-dscresource
Get-Command : Object reference not set to an instance of an object.
At
C:\windows\system32\windowspowershell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2261
char:27

  •         $resources += Get-Command -CommandType Configuration | ForEach-Objec ...
    
  •                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:slight_smile: [Get-Command], NullReferenceException
    • FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand

PS C:\Program Files\WindowsPowerShell\modules> $psversiontable

Name Value


PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18444
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2

Microsoft included “v1.0” in the default path to PowerShell’s installation directory originally, and now they’re sort of stuck with it. You can ignore that part.

That said, I’m not sure what’s causing the actual error here. I don’t see anything there that looks like it should be able to produce a null reference exception.

Thanks Dave. It looks like it is an issue running get-command rather than an issue running get-dscresource. I’ve only recently upgraded to v4. I do have SQL Server on this machine, which may have some bearing on this.

PS C:\Program Files\WindowsPowerShell\Modules> get-command
get-command : Object reference not set to an instance of an object.
At line:1 char:1

  • get-command
  •   + CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceException
      + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand

Is KB2883200 installed?

Don, thanks, no I don’t see it. I’m on Windows 7 (x64) not Windows 8.1. BTW, I don’t think this is a DSC issue, I need to get get-command working.

John,

Uninstalling the Windows Management Framework 4.0 (KB2819745) and reinstalling it (http://www.microsoft.com/en-gb/download/details.aspx?id=40855) after a restart might work for you on your Win7 machine.

Daniel, thanks, I’m trying this now. I’m not feeling very confident, because when WMF4 was uninstalled I could bring up the v3 ISE but get-command gave a similar error.

PS C:\Users\John> $psversiontable
get-command
show-command

Name Value


PSVersion 3.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18444
BuildVersion 6.2.9200.16481
PSCompatibleVersions {1.0, 2.0, 3.0}
PSRemotingProtocolVersion 2.2
get-command : Object reference not set to an instance of an object.
At line:2 char:1

  • get-command
  •   + CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceException
      + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand
    
    

get-command : Object reference not set to an instance of an object.
At line:1 char:3

  • @(get-command -CommandType Cmdlet,Function,Script,ExternalScript,Workflow),@(get …
  • + CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceException
    + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand

Uninstalling then reinstalling WMF4 did not fix get-command, which still errors, details below. Has anyone got any ideas what I may be doing wrong? This is on Windows 7 SP1 x64. We can probably close this topic, as I’ve raised another under “PowerShell Repair?” in the Q&A forum. [The issue is with get-command erroring, which is why Get-DSCResource is not working.]

PS C:\Users\John> $psversiontable

Name Value


PSVersion 4.0
WSManStackVersion 3.0
SerializationVersion 1.1.0.1
CLRVersion 4.0.30319.18444
BuildVersion 6.3.9600.16406
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion 2.2

PS C:\Users\John> get-command
get-command : Object reference not set to an instance of an object.
At line:1 char:1

  • get-command
  •   + CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceException
      + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand

This advice from Dave Wyatt fixed both get-command and Get-DSCResource on my machine, thank you all for your help

“Next, I’d try the modules. A quick way of seeing if this will be helpful is to rename your My Documents\WindowsPowerShell\Modules folder, launch PowerShell, and try Get-Command again. If it works, then you can try creating a new Modules folder and moving them in a few at a time. Hopefully, you’ll be able to identify one or more modules that are triggering this problem with Get-Command.”