DSC Resource Does not Exist

This topic contains 6 replies, has 2 voices, and was last updated by Profile photo of H Man H Man 1 year, 9 months ago.

  • Author
    Posts
  • #22407
    Profile photo of H Man
    H Man
    Participant

    Hi

    I am trying to use the xHyper-v resource to run a simple configuraiton.

    I keep getting this error when running Start-DscConfiguration "The PowerShell DSC resource MSFT_xVMSwitch does not exist at the PowerShell
    module path nor is it registered as a WMI DSC resource." When creating the MOF there is no error!!

    However when I run get-module -listavailable it's present. And when i run get-dscresoucre the xVMSwitch show thats its there as well

    Heres the Config

    Configuration MrHyperV_VM {
        param (
            [Parameter(Mandatory)]
            [string]$VMName,
            [Parameter(Mandatory)]
            [string]$baseVhdPath,
            [Parameter(Mandatory)]
            [string]$ParentPath,
            [Parameter(Mandatory)]
            [string]$VMSwitchName
        )
        Import-DscResource -module xHyper-V
        xVMSwitch switch {
            Name = $VMSwitchName
            Ensure = 'Present'
            Type = 'Internal'
        }
        xVHD DiffVHD {
            Ensure = 'Present'
            Name = $VMName
            Path = $baseVhdPath
            ParentPath = $ParentPath
            Generation = 'vhdx'
        }
        xVMHyperV CreateVM {
            Name = $VMName
            SwitchName = $VMSwitchName
            VhdPath = Join-Path -Path $baseVhdPath -ChildPath "$VMName.vhdx"
            ProcessorCount = 1
            MaximumMemory = 2GB
            MinimumMemory = 512MB
            RestartIfNeeded = 'True'
            DependsOn = '[xVHD]DiffVHD', '[xVMSwitch]switch'
            State = 'Running'
            Generation = 'vhdx'
        }
    }
    
    MrHyperV_VM -VMName HCTest02 -baseVhdPath 'V:\VMs' -ParentPath "V:\VMs\VHDs\HCFil01.vhdx" -VMSwitchName 'ethernetSwitch'
    
    Start-DscConfiguration -Wait -Path .\MrHyperV_VM -Verbose -Force
    

    Im at a lost any help would be greatly appreciated

  • #22408
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    What folder is the xHyper-V module in right now? I seem to remember reading that in the original WMF 4.0 release, you had to place these modules in C:\Program Files\WindowsPowerShell\Modules\ in order for the LCM to work properly (as opposed to putting them in some custom folder on the PSModulePath.)

    Are you getting this error at the MOF compliation step, or when you run Start-DscConfiguration?

  • #22409
    Profile photo of H Man
    H Man
    Participant

    The xHyper-v module is located in 2 places

    C:\Program Files\WindowsPowerShell\Modules

    and in $home\documents\windowspowershell\modules

    It happens when i run Start-DscConfiguration , the MOF does get created

    I am running PSverison 5 preview

  • #22410
    Profile photo of H Man
    H Man
    Participant

    I tried a v4 machine and it worked so must have something to do with the v5 Preview

  • #22411
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    And the folder contents are the same in both locations? Personally, I'd just remove the one in $home\Documents and leave the one in Program Files. That might fix the problem.

  • #22412
    Profile photo of H Man
    H Man
    Participant

    Thanks Dave I did that and on v4 Machine and it worked. As far as getting more examples for using the xhyper-v resource any suggestions?

  • #22413
    Profile photo of H Man
    H Man
    Participant

    I tested both locations and you were right The location needed to be moved ..thanks again

You must be logged in to reply to this topic.