Skip to content

Instantly share code, notes, and snippets.

@dennypc
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dennypc/9569df590dea5b8e7a58 to your computer and use it in GitHub Desktop.
Save dennypc/9569df590dea5b8e7a58 to your computer and use it in GitHub Desktop.
Vagrant Provisioning with Powershell DSC
param
(
[string]$nodeName = "localhost",
[string]$mofFolder = "C:\tmp\MOF\",
[ValidateNotNullOrEmpty()][string]$webProjectHome
)
Write-Host "MySite DSC Config :: nodeName=$nodeName, mofFolder=$mofFolder, webProjectHome=$webProjectHome"
# Clean up any existing MOF files
if (Test-Path($mofFolder))
{
Remove-Item $mofFolder -Recurse -Force
}
# Create MOF folder and set it as current location
New-Item -ItemType directory -Path $mofFolder | Out-Null
Set-Location $mofFolder | Out-Null
Configuration MySite
{
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]
$NodeName,
[string]
$SourcePath
)
Import-DscResource -Module xWebAdministration
Node $NodeName
{
WindowsFeature IIS
{
Ensure = "Present"
Name = "Web-Server"
}
File WebProject
{
Ensure = "Present"
SourcePath = $SourcePath
DestinationPath = "C:\inetpub\wwwroot"
Recurse = $true
Type = "Directory"
}
xWebsite DefaultSite
{
Ensure = "Present"
Name = "Default Web Site"
State = "Started"
PhysicalPath = "C:\inetpub\wwwroot"
DependsOn = @("[WindowsFeature]IIS", "[File]WebProject")
}
}
}
# DSC configuration data
$ConfigurationData = @{
AllNodes = @(
@{
NodeName = "*"
PSDscAllowPlainTextPassword = $true
}
)
}
MySite -ConfigurationData $ConfigurationData -NodeName $nodeName -SourcePath $webProjectHome
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment