Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 78 additions & 9 deletions DSCResources/MSFT_msWebAppPool/MSFT_msWebAppPool.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ function Get-TargetResource

if($AppPool -ne $null)
{
$Ensure = "Present"
$State = $AppPool.state
$Ensure = "Present"
$State = $AppPool.state
$IdentityType = $AppPool.processModel.identityType
If ($AppPool.processModel.Username -and $AppPool.processModel.Password)
{
$Cred = New-Object System.Management.Automation.PSCredential($AppPool.processModel.Username,(ConvertTo-SecureString -AsPlainText -Force -String $AppPool.processModel.Password))
}
}

$returnValue = @{
Name = $Name
Ensure = $Ensure
State = $State
Name = $Name
Ensure = $Ensure
State = $State
IdentityType = $IdentityType
Credential = $Cred
}

return $returnValue
Expand All @@ -53,7 +60,18 @@ function Set-TargetResource

[ValidateSet("Started","Stopped")]
[System.String]
$State = "Started"
$State = "Started",

[ValidateSet("SpecificUser","ApplicationPoolIdentity")]
[System.String]
$IdentityType,

[ValidateScript(
{
$IdentityType -eq "SpecificUser"
})]
[System.Management.Automation.PSCredential]
$Credential
)

if($Ensure -eq "Absent")
Expand All @@ -75,6 +93,34 @@ function Set-TargetResource
{
ExecuteRequiredState -Name $Name -State $State
}
if($IdentityType -and $IdentityType -ne $AppPool.identityType)
{
Write-Verbose "Setting AppPool IdentityType"
$ApplicationPool = Get-Item -Path IIS:\AppPools\* | ? {$_.name -eq $Name}
$ApplicationPool.processModel.identityType = $IdentityType
$ApplicationPool | Set-Item
}
if($Credential)
{
if($Credential.Username -ne $AppPool.Credential.Username -or
[System.Runtime.InteropServices.Marshal]::PtrToStringUni([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password)) -ne
[System.Runtime.InteropServices.Marshal]::PtrToStringUni([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($AppPool.Credential.Password)))
{
Write-Verbose "Setting Credential"
$ApplicationPool = Get-Item -Path IIS:\AppPools\* | ? {$_.name -eq $Name}
$ApplicationPool.processModel.Username = $Credential.Username
$ApplicationPool.processModel.Password = [System.Runtime.InteropServices.Marshal]::PtrToStringUni([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password))
$ApplicationPool | Set-Item
}
}
else
{
Write-Verbose "Removing Credential information"
$ApplicationPool = Get-Item -Path IIS:\AppPools\* | ? {$_.name -eq $Name}
$ApplicationPool.processModel.Username = ""
$ApplicationPool.processModel.Password = ""
$ApplicationPool | Set-Item
}
}
}

Expand All @@ -95,22 +141,45 @@ function Test-TargetResource

[ValidateSet("Started","Stopped")]
[System.String]
$State = "Started"
$State = "Started",

[ValidateSet("SpecificUser","ApplicationPoolIdentity")]
[System.String]
$IdentityType,

[ValidateScript(
{
$IdentityType -eq "SpecificUser"
})]
[System.Management.Automation.PSCredential]
$Credential
)
$WebAppPool = Get-TargetResource -Name $Name

if($Ensure -eq "Present")
{
if($WebAppPool.Ensure -eq $Ensure -and $WebAppPool.State -eq $state)

{
return $true
if(-not $Credential)
{
return $true
}
elseif($Credential.Username -eq $WebAppPool.Credential.Username -and
[System.Runtime.InteropServices.Marshal]::PtrToStringUni([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credential.Password)) -eq
[System.Runtime.InteropServices.Marshal]::PtrToStringUni([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($WebAppPool.Credential.Password)))
{
return $true
}
}
}
elseif($WebAppPool.Ensure -eq $Ensure)
{
return $true
}



return $false
}

Expand All @@ -129,4 +198,4 @@ function ExecuteRequiredState([string] $Name, [string] $State)
}
}

Export-ModuleMember -Function *-TargetResource
Export-ModuleMember -Function *-TargetResource
3 changes: 2 additions & 1 deletion DSCResources/MSFT_msWebAppPool/MSFT_msWebAppPool.schema.mof
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ class MSFT_msWebAppPool : 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;
[Write, Description("Identity type to run the AppPool under"), ValueMap{"SpecificUser","ApplicationPoolIdentity"}, Values{"SpecificUser","ApplicationPoolIdentity"}] String IdentityType;
[Write, Description("User/Password to run AppPool under"),EmbeddedInstance("MSFT_Credential")] String Credential;
};

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ function Get-TargetResource
[System.String]
$Website,

[parameter(Mandatory = $true)]
[System.String]
$WebApplication,
$WebApplication = "/",

[parameter(Mandatory = $true)]
[System.String]
Expand Down Expand Up @@ -54,9 +53,8 @@ function Set-TargetResource
[System.String]
$Website,

[parameter(Mandatory = $true)]
[System.String]
$WebApplication,
$WebApplication = "/",

[parameter(Mandatory = $true)]
[System.String]
Expand All @@ -66,6 +64,12 @@ function Set-TargetResource
[System.String]
$PhysicalPath,

[System.Management.Automation.PSCredential]
$Credential,

[System.Boolean]
$Force = $false,

[ValidateSet("Present","Absent")]
[System.String]
$Ensure = "Present"
Expand All @@ -79,12 +83,41 @@ function Set-TargetResource
if ($virtualDirectory.count -eq 0)
{
Write-Verbose "Creating new Web Virtual Directory $Name."
New-WebVirtualDirectory -Site $Website -Application $WebApplication -Name $Name -PhysicalPath $PhysicalPath
if ($WebApplication -eq "/")
{
New-WebVirtualDirectory -Site $Website -Name $Name -PhysicalPath $PhysicalPath -Force:$Force
$WebAppPath = "\"
}
else
{
New-WebVirtualDirectory -Site $Website -Application $WebApplication -Name $Name -PhysicalPath $PhysicalPath -Force:$Force
$WebAppPath = "\WebApplication\"
}
if ($Credential)
{
Set-ItemProperty -Path IIS:\Sites\$Website$WebAppPath$Name -Name userName -Value $Credential.Username
Set-ItemProperty -Path IIS:\Sites\$Website$WebAppPath$Name -Name password -Value $Credential.GetNetworkCredential().Password
}
}
else
{
Write-Verbose "Updating physical path for web virtual directory $Name."
Set-ItemProperty -Path IIS:Sites\$Website\$WebApplication\$Name -Name physicalPath -Value $PhysicalPath
if ($virtualDirectory.physicalPath -ne $PhysicalPath)
{
Write-Verbose "Updating physical path for web virtual directory $Name."
Set-ItemProperty -Path IIS:Sites\$Website$WebAppPath$Name -Name physicalPath -Value $PhysicalPath
}
if ($virtualDirectory.userName -ne $Credential.Username)
{
Write-Verbose "Updating Username for web virtual directory $Name"
Set-ItemProperty -Path IIS:Sites\$Website$WebAppPath$Name -Name userName -Value $Credential.Username
}
if ($virtualDirectory.password -ne $Credential.GetNetworkCredential().Password)
{
Write-Verbose "Updating Password for web virtual directory $Name"
Set-ItemProperty -Path IIS:Sites\$Website$WebAppPath$Name -Name password -Value $Credential.GetNetworkCredential().Password
}


}
}

Expand All @@ -105,9 +138,8 @@ function Test-TargetResource
[System.String]
$Website,

[parameter(Mandatory = $true)]
[System.String]
$WebApplication,
$WebApplication ="/",

[parameter(Mandatory = $true)]
[System.String]
Expand All @@ -117,6 +149,9 @@ function Test-TargetResource
[System.String]
$PhysicalPath,

[System.Management.Automation.PSCredential]
$Credential,

[ValidateSet("Present","Absent")]
[System.String]
$Ensure = "Present"
Expand All @@ -129,7 +164,9 @@ function Test-TargetResource

if ($virtualDirectory.count -eq 1 -and $Ensure -eq "Present")
{
if ($virtualDirectory.physicalPath -eq $PhysicalPath)
if ($virtualDirectory.physicalPath -eq $PhysicalPath -and
$virtualDirectory.userName -eq $Credential.Username -and
$virtualDirectory.password -eq $Credential.GetNetworkCredential().Password)
{
Write-Verbose "Web virtual directory is in required state"
return $true
Expand Down Expand Up @@ -198,6 +235,12 @@ function CheckApplicationExists
[System.String]
$Application
)

if ($Application -eq "/")
{
return $true
}

$WebApplication = Get-WebApplication -Site $Site -Name $Application

if ($WebApplication.count -eq 1)
Expand All @@ -223,8 +266,12 @@ function GetCompositeVirtualDirectoryName
$Application
)

if ($Application -eq "/")
{
return $Name
}

return "$Application/$Name"
}

Export-ModuleMember -Function *-TargetResource

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
class MSFT_msWebVirtualDirectory : OMI_BaseResource
{
[Key, Description("Name of website with which Web Application is associated")] string Website;
[Key, Description("Web application name for the virtual directory")] string WebApplication;
[Write, Description("Web application name for the virtual directory")] string WebApplication;
[Key, Description("Name of virtual directory")] string Name;
[Required, Description("Physical path for the virtual directory")] string PhysicalPath;
[Write, Description("The Username/Password to run this Virtual Directory under"),EmbeddedInstance("MSFT_Credential")] String Credential;
[Write] boolean Force;
[Write, Description("Whether virtual directory should be present or absent"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure;
};

2 changes: 1 addition & 1 deletion DSCResources/MSFT_msWebsite/MSFT_msWebsite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Get-TargetResource
State = $Website.state;
ID = $Website.id;
ApplicationPool = $Website.applicationPool;
BindingInfo = $CimBindings;
#BindingInfo = $CimBindings;
DefaultPage = $allDefaultPage
}

Expand Down