diff --git a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1 b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1
index 4423852fe..01f20859b 100644
--- a/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1
+++ b/DSCResources/MSFT_xIisMimeTypeMapping/MSFT_xIisMimeTypeMapping.psm1
@@ -4,169 +4,184 @@ Import-Module -Name "$PSScriptRoot\..\Helper.psm1"
# Localized messages
data LocalizedData
{
- # culture="en-US"
- ConvertFrom-StringData -StringData @'
- NoWebAdministrationModule = Please ensure that WebAdministration module is installed.
- AddingType = Adding MIMEType '{0}' for extension '{1}'
- RemovingType = Removing MIMEType '{0}' for extension '{1}'
- TypeExists = MIMEType '{0}' for extension '{1}' already exist
- TypeNotPresent = MIMEType '{0}' for extension '{1}' is not present as requested
- TypeStatusUnknown = MIMEType '{0}' for extension '{1}' is is an unknown status
- VerboseGetTargetPresent = MIMEType is present
- VerboseGetTargetAbsent = MIMEType is absent
- VerboseSetTargetError = Cannot set type
+ # culture="en-US"
+ ConvertFrom-StringData -StringData @'
+ NoWebAdministrationModule = Please ensure that WebAdministration module is installed.
+ AddingType = Adding MIMEType '{0}' for extension '{1}'
+ UpdatingType = Updating MIMEType to '{0}' for extension '{1}'
+ RemovingType = Removing MIMEType '{0}' for extension '{1}'
+ TypeExists = MIMEType '{0}' for extension '{1}' already exist
+ TypeNotPresent = MIMEType '{0}' for extension '{1}' is not present as requested
+ TypeStatusUnknown = MIMEType '{0}' for extension '{1}' is is an unknown status
+ VerboseGetTargetPresent = MIMEType is present
+ VerboseGetTargetAbsent = MIMEType is absent
+ VerboseSetTargetError = Cannot set type
'@
}
function Get-TargetResource
{
- <#
- .SYNOPSIS
- This will return a hashtable of results
- #>
- [OutputType([Hashtable])]
- param
- (
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [String] $Extension,
-
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [String] $MimeType,
-
- [ValidateSet('Present', 'Absent')]
- [Parameter(Mandatory)]
- [String] $Ensure
- )
-
- # Check if WebAdministration module is present for IIS cmdlets
- Assert-Module
-
- $mt = Get-Mapping -Extension $Extension -Type $MimeType
-
- if ($null -eq $mt)
- {
- Write-Verbose -Message $LocalizedData.VerboseGetTargetAbsent
- return @{
- Ensure = 'Absent'
- Extension = $null
- MimeType = $null
- }
- }
- else
- {
- Write-Verbose -Message $LocalizedData.VerboseGetTargetPresent
- return @{
- Ensure = 'Present'
- Extension = $mt.fileExtension
- MimeType = $mt.mimeType
- }
- }
+ <#
+ .SYNOPSIS
+ This will return a hashtable of results
+ #>
+ [OutputType([Hashtable])]
+ param
+ (
+ [Parameter(Mandatory)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Extension,
+
+ [Parameter(Mandatory)]
+ [ValidateNotNullOrEmpty()]
+ [String] $MimeType,
+
+ [ValidateSet('Present', 'Absent')]
+ [Parameter(Mandatory)]
+ [String] $Ensure
+ )
+
+ # Check if WebAdministration module is present for IIS cmdlets
+ Assert-Module
+
+ $mt = Get-Mapping -Extension $Extension -Type $MimeType
+
+ if ($null -eq $mt)
+ {
+ Write-Verbose -Message $LocalizedData.VerboseGetTargetAbsent
+ return @{
+ Ensure = 'Absent'
+ Extension = $null
+ MimeType = $null
+ }
+ }
+ else
+ {
+ Write-Verbose -Message $LocalizedData.VerboseGetTargetPresent
+ return @{
+ Ensure = 'Present'
+ Extension = $mt.fileExtension
+ MimeType = $mt.mimeType
+ }
+ }
}
function Set-TargetResource
{
- <#
- .SYNOPSIS
- This will set the desired state
- #>
- param
- (
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [String] $Extension,
-
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [String] $MimeType,
-
- [ValidateSet('Present', 'Absent')]
- [Parameter(Mandatory)]
- [String] $Ensure
- )
-
- Assert-Module
-
- [String] $psPathRoot = 'MACHINE/WEBROOT/APPHOST'
- [String] $sectionNode = 'system.webServer/staticContent'
-
- $mt = Get-Mapping -Extension $Extension -Type $MimeType
-
- if ($null -eq $mt -and $Ensure -eq 'Present')
- {
- # add the MimeType
- Add-WebConfigurationProperty -PSPath $psPathRoot `
- -Filter $sectionNode `
- -Name '.' `
- -Value @{fileExtension="$Extension";mimeType="$MimeType"}
- Write-Verbose -Message ($LocalizedData.AddingType -f $MimeType,$Extension);
- }
- elseif ($null -ne $mt -and $Ensure -eq 'Absent')
- {
- # remove the MimeType
- Remove-WebConfigurationProperty -PSPath $psPathRoot `
- -Filter $sectionNode `
- -Name '.' `
- -AtElement @{fileExtension="$Extension"}
- Write-Verbose -Message ($LocalizedData.RemovingType -f $MimeType,$Extension);
- }
- else
- {
- Write-Verbose -Message $LocalizedData.VerboseSetTargetError
- }
+ <#
+ .SYNOPSIS
+ This will set the desired state
+ #>
+ param
+ (
+ [Parameter(Mandatory)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Extension,
+
+ [Parameter(Mandatory)]
+ [ValidateNotNullOrEmpty()]
+ [String] $MimeType,
+
+ [ValidateSet('Present', 'Absent')]
+ [Parameter(Mandatory)]
+ [String] $Ensure
+ )
+
+ Assert-Module
+
+ [String] $psPathRoot = 'MACHINE/WEBROOT/APPHOST'
+ [String] $sectionNode = 'system.webServer/staticContent'
+
+ # $mt = Get-Mapping -Extension $Extension -Type $MimeType
+ $mt = Get-Mapping -Extension $Extension
+
+ if ($Ensure -eq 'Present')
+ {
+ if ( ! $mt )
+ {
+ # add the MimeType
+ Add-WebConfigurationProperty -PSPath $psPathRoot `
+ -Filter $sectionNode `
+ -Name '.' `
+ -Value @{fileExtension="$Extension";mimeType="$MimeType"}
+ Write-Verbose -Message ($LocalizedData.AddingType -f $MimeType,$Extension);
+ }
+ else
+ {
+ # update the MimeType
+ Set-WebConfigurationProperty -PSPath $psPathRoot `
+ -Filter "$sectionNode/mimeMap[@fileExtension='$Extension']" `
+ -Name '.' `
+ -Value @{fileExtension="$Extension";mimeType="$MimeType"}
+ Write-Verbose -Message ($LocalizedData.UpdatingType -f $MimeType,$Extension);
+ }
+
+ }
+ elseif ($null -ne $mt -and $Ensure -eq 'Absent')
+ {
+ # remove the MimeType
+ Remove-WebConfigurationProperty -PSPath $psPathRoot `
+ -Filter $sectionNode `
+ -Name '.' `
+ -AtElement @{fileExtension="$Extension"}
+ Write-Verbose -Message ($LocalizedData.RemovingType -f $MimeType,$Extension);
+ }
+ else
+ {
+ Write-Verbose -Message $LocalizedData.VerboseSetTargetError
+ }
}
function Test-TargetResource
{
- <#
- .SYNOPSIS
- This tests the desired state. If the state is not correct it will return $false.
- If the state is correct it will return $true
- #>
-
- [OutputType([System.Boolean])]
- param
- (
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [String] $Extension,
-
- [Parameter(Mandatory)]
- [ValidateNotNullOrEmpty()]
- [String] $MimeType,
-
- [ValidateSet('Present', 'Absent')]
- [Parameter(Mandatory)]
- [String] $Ensure
- )
-
- [Boolean] $DesiredConfigurationMatch = $true;
-
- Assert-Module
-
- $mt = Get-Mapping -Extension $Extension -Type $MimeType
-
- if (($null -eq $mt -and $Ensure -eq 'Present') -or ($null -ne $mt -and $Ensure -eq 'Absent'))
- {
- $DesiredConfigurationMatch = $false;
- }
- elseif ($null -ne $mt -and $Ensure -eq 'Present')
- {
- # Already there
- Write-Verbose -Message ($LocalizedData.TypeExists -f $MimeType,$Extension);
- }
- elseif ($null -eq $mt -and $Ensure -eq 'Absent')
- {
- # TypeNotPresent
- Write-Verbose -Message ($LocalizedData.TypeNotPresent -f $MimeType,$Extension);
- }
- else
- {
- $DesiredConfigurationMatch = $false;
- Write-Verbose -Message ($LocalizedData.TypeStatusUnknown -f $MimeType,$Extension);
- }
-
- return $DesiredConfigurationMatch
+ <#
+ .SYNOPSIS
+ This tests the desired state. If the state is not correct it will return $false.
+ If the state is correct it will return $true
+ #>
+
+ [OutputType([System.Boolean])]
+ param
+ (
+ [Parameter(Mandatory)]
+ [ValidateNotNullOrEmpty()]
+ [String] $Extension,
+
+ [Parameter(Mandatory)]
+ [ValidateNotNullOrEmpty()]
+ [String] $MimeType,
+
+ [ValidateSet('Present', 'Absent')]
+ [Parameter(Mandatory)]
+ [String] $Ensure
+ )
+
+ [Boolean] $DesiredConfigurationMatch = $true;
+
+ Assert-Module
+
+ $mt = Get-Mapping -Extension $Extension -Type $MimeType
+
+ if (($null -eq $mt -and $Ensure -eq 'Present') -or ($null -ne $mt -and $Ensure -eq 'Absent'))
+ {
+ $DesiredConfigurationMatch = $false;
+ }
+ elseif ($null -ne $mt -and $Ensure -eq 'Present')
+ {
+ # Already there
+ Write-Verbose -Message ($LocalizedData.TypeExists -f $MimeType,$Extension);
+ }
+ elseif ($null -eq $mt -and $Ensure -eq 'Absent')
+ {
+ # TypeNotPresent
+ Write-Verbose -Message ($LocalizedData.TypeNotPresent -f $MimeType,$Extension);
+ }
+ else
+ {
+ $DesiredConfigurationMatch = $false;
+ Write-Verbose -Message ($LocalizedData.TypeStatusUnknown -f $MimeType,$Extension);
+ }
+
+ return $DesiredConfigurationMatch
}
#region Helper Functions
@@ -174,17 +189,25 @@ function Test-TargetResource
function Get-Mapping
{
- [CmdletBinding()]
- param
- (
- [String] $Extension,
-
- [String] $Type
- )
-
- [String] $filter = "system.webServer/staticContent/mimeMap[@fileExtension='" + `
- $Extension + "' and @mimeType='" + $Type + "']"
- return Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter $filter -Name .
+ [CmdletBinding()]
+ param
+ (
+ [String] $Extension,
+
+ [String] $Type = $null
+ )
+
+ [String] $filter = "system.webServer/staticContent/mimeMap"
+ if ( $Type )
+ {
+ $filter += "[@fileExtension='$Extension' and @mimeType='$Type']"
+ }
+ else
+ {
+ $filter += "[@fileExtension='$Extension']"
+ }
+
+ return Get-WebConfigurationProperty -PSPath 'MACHINE/WEBROOT/APPHOST' -Filter $filter -Name .
}
#endregion
diff --git a/xWebAdministration.pssproj b/xWebAdministration.pssproj
new file mode 100644
index 000000000..47027ca5a
--- /dev/null
+++ b/xWebAdministration.pssproj
@@ -0,0 +1,137 @@
+
+
+
+ Debug
+ 2.0
+ 6CAFC0C6-A428-4d30-A9F9-700E829FEA51
+ Exe
+ MyApplication
+ MyApplication
+ xWebAdministration
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/xWebAdministration.pssproj.user b/xWebAdministration.pssproj.user
new file mode 100644
index 000000000..5283ef199
--- /dev/null
+++ b/xWebAdministration.pssproj.user
@@ -0,0 +1,6 @@
+
+
+
+ ShowAllFiles
+
+
\ No newline at end of file