I'm a beginner to Desired State Configuration, but I've been having some trouble doing something kind of basic.
My configuration is essentially install IIS (including Web Management and some other parts), run some installers then stop the default website.
I've chosen to not to use the xWebAdministration module due to the fact it seems like overkill just to stop the default website. So, I've written the following script to complete this task:
Script StopDefaultWebsite {
SetScript = {
# Check if WebAdministration module is present for IIS cmdlets
if(!(Get-Module -ListAvailable -Name WebAdministration))
{
Throw "Please ensure that WebAdministration module is installed."
}
Stop-Website "Default Web Site"
}
TestScript = {
$w = Get-Website | where {$_.name -eq "Default Web Site"}
return $w.state -eq "Stopped"
}
GetScript = {
$installStatus = Get-Website | where {$_.name -eq "Default Web Site"}
@{
SetScript = $SetScript
TestScript = $TestScript
Result = [String]$installStatus;
}
}
}
(I've copied the first part of the SetScript from xWebAdministration) The problem I have is when I start the configuration the windows feature "web-mgmt-service" gets installed fine and I can check it's installed but when this script runs I get the following error:
PowerShell provider MSFT_ScriptResource failed to execute Test-TargetResource functionality with error message:
Could not load file or assembly 'Microsoft.IIS.PowerShell.Framework' or one of its dependencies. The system cannot find the file specified.
+ CategoryInfo : InvalidOperation: (:) [], CimException
+ FullyQualifiedErrorId : ProviderOperationExecutionFailure
I'm guessing this is because either the machine needs to restart or at least Powershell needs to restart before the IIS powershell module can be loaded. This can be seen when I try to start the exact same configuration again and it will succeed.
I've tried restarting the machine and that causes even more issues. Is there any way I can restart Powershell? Or is there something more basic I can do to load the IIS Powershell Module.
Thanks
You don't have to restart. All you have to do is reload the $env:PSModulePath
variable. Once you refresh the value of this variable, you will be able to load the newly added modules. I use this trick for unattended SQL installs where I used to face the same problem.