Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install and import module before call DSC in the same script?

Tags:

powershell

dsc

I am trying to create a script which will prepare my web server. VM is Windows Server 2016 clean installation without any adjustments and imported modules and configurations. Inside the script, I have a mix of functions and DSC configuration for installing .NET, create directories, join to the domain. At the beginning of the script, I call:

Install-PackageProvider -Name Nuget... Install-Module xWebAdmin... Import-Module ...

Then some functions, and DSC configurations. When I run a script, first go to DSC configuration and displaying error from the image below.

I do not know how and where in my script, first to install all necessary packages and modules and then execute rest of the script and configuration.

As I do not have installed and imported modules xWindowsUpdate, xWebAdministration, this won't execute, even if I put import-module at the beginning of the script.

Install-Module -Name xWebAdministration -Force
Install-Module -Name xWindowsUpdate -Force 

Configuration IIS
{  
Import-DscResource –ModuleName PSDesiredStateConfiguration, xWindowsUpdate, 
xWebAdministration

Node "localhost"
{  
    {
        Ensure = "Present" 
        Type = "Directory" 
        DestinationPath = "C:\DSCDeployment"    
    }

Any hint and advice?

enter image description here

like image 344
Branko Avatar asked Oct 28 '22 19:10

Branko


1 Answers

It seems that it's not possible to do install module and call DSC config in the same file. First, PowerShell will parse the Configuration and will try to resolve the Import-DSCResource keywords (and fail because they're not available). It has to be done in 2 separate files...

like image 153
Branko Avatar answered Nov 08 '22 06:11

Branko