Get-DSCResource Error

This topic contains 8 replies, has 4 voices, and was last updated by  John Drake 3 years, 2 months ago.

  • Author
    Posts
  • #15338

    John Drake
    Participant

    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: (:) [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

  • #15339

    Dave Wyatt
    Moderator

    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.

  • #15340

    John Drake
    Participant

    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

  • #15344

    Don Jones
    Keymaster

    Is KB2883200 installed?

  • #15345

    John Drake
    Participant

    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.

  • #15350

    Daniel Krebs
    Moderator

    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.

  • #15357

    John Drake
    Participant

    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

  • #15359

    John Drake
    Participant

    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

  • #15497

    John Drake
    Participant

    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."

You must be logged in to reply to this topic.