The term Import-DscResource is not recognized

I have a fresh new Win 2K12 R2, with Feb 2015 preview installed and downloaded “DSC Resourc Kit Wave 10 182015.zip”, AllResources directory put under C:\Program Files\WindowsPowerShell\Modules
I copied the example configuration provided to set up a new IIS website. 1st of all, I get a quiugly broken redline on xWebsite, indicating "Undefined DSC resource ‘xWebsite’. Use Import-DSCResource to import the resource.
“Import-DscResource -Module xWebAdministration” is declared in the begining of the script, when I run the script I get
“The term 'Import-DscResource is not recognized as the name of a cmdlet…”

I searched this site, followed, what I was able to understand that fix KB2883200 is is “InstalledOn = 3/24/2015”, yesterday.

Issuing Get-Dsecresource, I can see clearly 2 modules, “xWebApplication and xWebVirtualDirectory”.

Also, I discovered that Import-DscResource is not recognized neither on the commandline nor in the help in ISE

What can be missing? Thanks in advance

Import-DscResource is actually a dynamic keyword which is only available inside a configuration function. That makes it not terribly discoverable, unfortunately, but it’s what we’ve got. If you write an empty configuration and then type Import-DscResource, though, you’ll get intellisense / tab completion for its parameters (-ModuleName and -Name)

Out of curiosity, have you tried doing this with WMF4.0? WMF5.0 is very very very beta, and it’d be nice to know if you have the same problems with the current production-level code.

Yes, Dave, I get the intellisense in ISE, but still have the red broken squigly line on the lines where there is xWebsite and when running the script it errors right away as follows £

}
At line:44 char:9

  •     xWebsite DefaultSite
    
  •     ~~~~~~~~
    

Undefined DSC resource ‘xWebsite’. Use Import-DSCResource to import the resource.
At line:65 char:9

  •     xWebsite NewWebsite
    
  •     ~~~~~~~~
    

Undefined DSC resource ‘xWebsite’. Use Import-DSCResource to import the resource.
+ CategoryInfo : ParserError: (:slight_smile: [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ResourceNotDefined

No Don, As I said, it is a lab that I created yesterday with 3 fresh VMs all win2k12R2 abd went with the Feb 2015 version
Are you suggesting desinstalling the WMF 5 preview, install the version 4?

I can’t see your full configuration, but it should look something like this:

configuration Whatever
{
    Import-DscResource -ModuleName xWebAdministration

    node SomeNode
    {
        xWebsite theWebsite
        {
            # etc
        }
    }
}

With that setup, as long as your xWebAdministration module is somewhere on the machine PSModulePath (typically in C:\Program Files\WindowsPowerShell\Modules), you should be all set.

This is the script I am trying to run which I copied from the url https://gallery.technet.microsoft.com/DSC-Resource-Kit-All-c449312d

configuration Sample_xWebsite_NewWebsite
{
param
(
# Target nodes to apply the configuration
[string[]]$NodeName = ‘localhost’,

    # Name of the website to create 
    [Parameter(Mandatory)] 
    [ValidateNotNullOrEmpty()] 
    [String]$WebSiteName, 

    # Source Path for Website content 
    [Parameter(Mandatory)] 
    [ValidateNotNullOrEmpty()] 
    [String]$SourcePath, 

    # Destination path for Website content 
    [Parameter(Mandatory)] 
    [ValidateNotNullOrEmpty()] 
    [String]$DestinationPath 
) 

# Import the module that defines custom resources 
Import-DscResource -Module xWebAdministration 

Node $NodeName 
{ 
    # Install the IIS role 
    WindowsFeature IIS 
    { 
        Ensure          = "Present" 
        Name            = "Web-Server" 
    } 

    # Install the ASP .NET 4.5 role 
    WindowsFeature AspNet45 
    { 
        Ensure          = "Present" 
        Name            = "Web-Asp-Net45" 
    } 

    # Stop the default website 
    xWebsite DefaultSite  
    { 
        Ensure          = "Present" 
        Name            = "Default Web Site" 
        State           = "Stopped" 
        PhysicalPath    = "C:\inetpub\wwwroot" 
        DependsOn       = "[WindowsFeature]IIS" 
    } 

    # Copy the website content 
    File WebContent 
    { 
        Ensure          = "Present" 
        SourcePath      = $SourcePath 
        DestinationPath = $DestinationPath 
        Recurse         = $true 
        Type            = "Directory" 
        DependsOn       = "[WindowsFeature]AspNet45" 
    }        

    # Create the new Website with HTTPS 
    xWebsite NewWebsite 
    { 
        Ensure          = "Present" 
        Name            = $WebSiteName 
        State           = "Started" 
        PhysicalPath    = $DestinationPath 
        BindingInfo     = MSFT_xWebBindingInformation 
                         { 
                           Protocol              = "HTTPS" 
                           Port                  = 8443 
                           CertificateThumbprint ="71AD93562316F21F74606F1096B85D66289ED60F" 
                           CertificateStoreName  = "WebHosting" 
                         } 
        DependsOn       = "[File]WebContent" 
    } 
} 

}

Do you have any red squiggles in the ISE under the call to Import-DscResource?

Nevermind. This is their TechNet gallery publishing problem again. The last few revisions of the DSC resource kit have been missing resources from the zip file for some reason, and I guess they haven’t got it sorted out yet. Just delete the whole xWebAdministration module from your computer.

If you’re running the PowerShell 5.0 preview, you can run this command instead to get the module (which has all of the intended DSC resources). You’ll need to be running PowerShell with the “Run As Administrator” option for this command to work:

Install-Module xWebAdministration -Force

So many thanks Dave, appreicate your help, it is working like a charm now., one thing to correct for anybody who lands here, we need to add the -Name switch for the command

Install-Module -Name xWebAdministration -Force

Otherwise it does not work.

Tell me, should I do this process for all the other resources?

Couldn’t hurt. I’d be very surprised if this is the only module in that zip file that is missing resources, and if you intend to use them, you may as well make sure you have all of the bits.