-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 056156c
Showing
23 changed files
with
3,942 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
[ClassVersion("1.0.0"), FriendlyName("xIisModule")] | ||
class MSFT_xIisModule : OMI_BaseResource | ||
{ | ||
[Key, Description("The path to the module, usually a dll, to be added to IIS.")] String Path; | ||
[Required, Description("The logical name of the module to add to IIS.")] String Name; | ||
[Required, Description("The allowed request Path example: *.php")] String RequestPath; | ||
[Required, Description("The supported verbs for the module.")] String Verb[]; | ||
[Write, Description("The IIS Site to register the module.")] String SiteName; | ||
[Write, Description("Should the module be present or absent."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; | ||
[Write, Description("The type of the module."), ValueMap{"FastCgiModule"}, Values{"FastCgiModule"}] String ModuleType; | ||
[Read, Description("The End Point is setup. Such as a Fast Cgi endpoint.")] Boolean EndPointSetup; | ||
}; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
$diff = join-Path ${env:ProgramFiles(x86)} "Beyond compare 2\bc2.exe" | ||
$friendlyName = "xIisModule" | ||
$resourceName = "MSFT_$friendlyName" | ||
$classVersion = "1.0.0" | ||
|
||
$scriptRoot = Split-Path $MyInvocation.MyCommand.Path | ||
$originalModuleRoot = join-Path $scriptroot "..\.." | ||
$originalModuleRootPath = Resolve-Path $originalModuleRoot | ||
$moduleRoot = Join-Path $env:temp "$($originalModuleRootPath.path | split-path -Leaf)Temp" | ||
|
||
$resources = @() | ||
$schemaPath = (join-path $scriptRoot "$resourceName.schema.mof") | ||
|
||
#Key properties | ||
$resources += New-xDscResourceProperty -Name Path -Type String -Attribute Key -Description "The path to the module, usually a dll, to be added to IIS." | ||
|
||
|
||
#Required Properites | ||
$resources += New-xDscResourceProperty -Name Name -Type String -Attribute Required -Description "The logical name of the module to add to IIS." | ||
$resources += New-xDscResourceProperty -Name RequestPath -Type String -Attribute Required -Description "The allowed request Path example: *.php" | ||
$resources += New-xDscResourceProperty -Name Verb -Type String[] -Attribute Required -Description "The supported verbs for the module." | ||
|
||
#Write Properties | ||
$resources += New-xDscResourceProperty -Name SiteName -Type String -Attribute Write -Description "The IIS Site to register the module." | ||
$resources += New-xDscResourceProperty -Name Ensure -Type String -Attribute Write -Description "Should the module be present or absent." -ValidateSet @("Present","Absent") | ||
$resources += New-xDscResourceProperty -Name ModuleType -Type String -Attribute Write -Description "The type of the module." -ValidateSet @("FastCgiModule") | ||
|
||
#Read Properties | ||
$resources += New-xDscResourceProperty -Name EndPointSetup -Type Boolean -Attribute Read -Description "The End Point is setup. Such as a Fast Cgi endpoint." | ||
|
||
|
||
|
||
Write-Host updating... | ||
|
||
# Create a New template resource to a temporary folder | ||
New-xDscResource -Property $resources -ClassVersion $classVersion -Name $resourceName -Path $moduleRoot -FriendlyName $friendlyName | ||
|
||
|
||
# Use your favorite diff program to compare and merge the current resource and the existing resource | ||
|
||
if((test-Path $diff)) | ||
{ | ||
&$diff $originalModuleRoot $moduleRoot | ||
} | ||
else | ||
{ | ||
Write-Warning "Diff propgram not found!`r`nUse your favorite diff program to compare and merge:`r`n `t$($originalModuleRootPath.path)`r`n and:`r`n `t$moduleRoot" | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name | ||
) | ||
|
||
$Ensure = "Absent" | ||
$State = "Stopped" | ||
|
||
#need to import explicitly to run for IIS:\AppPools | ||
Import-Module WebAdministration | ||
|
||
if(!(Get-Module -ListAvailable -Name WebAdministration)) | ||
{ | ||
Throw "Please ensure that WebAdministration module is installed." | ||
} | ||
|
||
$AppPool = Get-Item -Path IIS:\AppPools\* | ? {$_.name -eq $Name} | ||
|
||
if($AppPool -ne $null) | ||
{ | ||
$Ensure = "Present" | ||
$State = $AppPool.state | ||
} | ||
|
||
$returnValue = @{ | ||
Name = $Name | ||
Ensure = $Ensure | ||
State = $State | ||
} | ||
|
||
return $returnValue | ||
} | ||
|
||
|
||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name, | ||
|
||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present", | ||
|
||
[ValidateSet("Started","Stopped")] | ||
[System.String] | ||
$State = "Started" | ||
) | ||
|
||
if($Ensure -eq "Absent") | ||
{ | ||
Write-Verbose("Removing the Web App Pool") | ||
Remove-WebAppPool $Name | ||
} | ||
else | ||
{ | ||
$AppPool = Get-TargetResource -Name $Name | ||
if($AppPool.Ensure -ne "Present") | ||
{ | ||
Write-Verbose("Creating the Web App Pool") | ||
New-WebAppPool $Name | ||
$AppPool = Get-TargetResource -Name $Name | ||
} | ||
|
||
if($AppPool.State -ne $State) | ||
{ | ||
ExecuteRequiredState -Name $Name -State $State | ||
} | ||
} | ||
} | ||
|
||
|
||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name, | ||
|
||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present", | ||
|
||
[ValidateSet("Started","Stopped")] | ||
[System.String] | ||
$State = "Started" | ||
) | ||
$WebAppPool = Get-TargetResource -Name $Name | ||
|
||
if($Ensure -eq "Present") | ||
{ | ||
if($WebAppPool.Ensure -eq $Ensure -and $WebAppPool.State -eq $state) | ||
{ | ||
return $true | ||
} | ||
} | ||
elseif($WebAppPool.Ensure -eq $Ensure) | ||
{ | ||
return $true | ||
} | ||
|
||
return $false | ||
} | ||
|
||
|
||
function ExecuteRequiredState([string] $Name, [string] $State) | ||
{ | ||
if($State -eq "Started") | ||
{ | ||
Write-Verbose("Starting the Web App Pool") | ||
start-WebAppPool -Name $Name | ||
} | ||
else | ||
{ | ||
Write-Verbose("Stopping the Web App Pool") | ||
Stop-WebAppPool -Name $Name | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
[ClassVersion("1.0.0.0"), FriendlyName("xWebAppPool")] | ||
class MSFT_xWebAppPool : OMI_BaseResource | ||
{ | ||
[Key, Description("Name of the Web Application Pool")] String Name; | ||
[Write, Description("Web Application Pool Present/Absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure; | ||
[Write, Description("State of Web Application Pool"), ValueMap{"Started","Stopped"}, Values{"Started","Stopped"}] String State; | ||
}; | ||
|
||
|
||
|
180 changes: 180 additions & 0 deletions
180
DSCResources/MSFT_xWebApplication/MSFT_xWebApplication.psm1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
function Get-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.Hashtable])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Website, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$WebAppPool, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$PhysicalPath | ||
) | ||
|
||
CheckDependencies | ||
|
||
$webApplication = Get-WebApplication -Site $Website -Name $Name | ||
|
||
$PhysicalPath = "" | ||
$Ensure = "Absent" | ||
$WebAppPool = "" | ||
|
||
if ($webApplication.Count -eq 1) | ||
{ | ||
$PhysicalPath = $webApplication.PhysicalPath | ||
$WebAppPool = $webApplication.applicationPool | ||
$Ensure = "Present" | ||
} | ||
|
||
$returnValue = @{ | ||
Website = $Website | ||
Name = $Name | ||
WebAppPool = $WebAppPool | ||
PhysicalPath = $PhysicalPath | ||
Ensure = $Ensure | ||
} | ||
|
||
return $returnValue | ||
} | ||
|
||
|
||
function Set-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Website, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$WebAppPool, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$PhysicalPath, | ||
|
||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present" | ||
) | ||
|
||
CheckDependencies | ||
|
||
if ($Ensure -eq "Present") | ||
{ | ||
$webApplication = Get-WebApplication -Site $Website -Name $Name | ||
if ($webApplication.count -eq 0) | ||
{ | ||
Write-Verbose "Creating new Web application $Name." | ||
New-WebApplication -Site $Website -Name $Name -PhysicalPath $PhysicalPath -ApplicationPool $WebAppPool | ||
} | ||
else | ||
{ | ||
if ($webApplication.physicalPath -ne $PhysicalPath) | ||
{ | ||
Write-Verbose "Updating physical path for Web application $Name." | ||
Set-ItemProperty -Path IIS:Sites\$Website\$Name -Name physicalPath -Value $PhysicalPath | ||
} | ||
if ($webApplication.applicationPool -ne $ApplicationPool) | ||
{ | ||
Write-Verbose "Updating physical path for Web application $Name." | ||
Set-ItemProperty -Path IIS:Sites\$Website\$Name -Name applicationPool -Value $WebAppPool | ||
} | ||
} | ||
} | ||
|
||
if ($Ensure -eq "Absent") | ||
{ | ||
Write-Verbose "Removing existing Web Application $Name." | ||
Remove-WebApplication -Site $Website -Name $Name | ||
} | ||
} | ||
|
||
|
||
function Test-TargetResource | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Website, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$Name, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$WebAppPool, | ||
|
||
[parameter(Mandatory = $true)] | ||
[System.String] | ||
$PhysicalPath, | ||
|
||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = "Present" | ||
) | ||
|
||
CheckDependencies | ||
|
||
$webApplication = Get-WebApplication -Site $Website -Name $Name | ||
|
||
if ($webApplication.count -eq 1 -and $Ensure -eq "Present") { | ||
if ($webApplication.physicalPath -ne $PhysicalPath) | ||
{ | ||
Write-Verbose "Physical path for web application $Name does not match desired state." | ||
return $false | ||
} | ||
elseif ($webApplication.applicationPool -ne $WebAppPool) | ||
{ | ||
Write-Verbose "Web application pool for web application $Name does not match desired state." | ||
return $false | ||
} | ||
else | ||
{ | ||
Write-Verbose "Web application pool matches desired state." | ||
return $true | ||
} | ||
} | ||
|
||
if ($webApplication.count -eq 0 -and $Ensure -eq "Absent") { | ||
Write-Verbose "Web application $Name should be absent and is absent." | ||
return $true | ||
} | ||
|
||
return $false | ||
} | ||
|
||
function CheckDependencies | ||
{ | ||
Write-Verbose "Checking whether WebAdministration is there in the machine or not." | ||
# Check if WebAdministration module is present for IIS cmdlets | ||
if(!(Get-Module -ListAvailable -Name WebAdministration)) | ||
{ | ||
Throw "Please ensure that WebAdministration module is installed." | ||
} | ||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource | ||
|
||
|
||
|
Oops, something went wrong.