Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #886 from jensotto/spwebapppropertybag
SPWebAppPropertyBag: Added new resource for managing web application property bag.
- Loading branch information
Showing
7 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
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
169 changes: 169 additions & 0 deletions
169
Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.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,169 @@ | ||
function Get-TargetResource() | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Collections.HashTable])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$WebAppUrl, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$Key, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$Value, | ||
|
||
[Parameter()] | ||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = 'Present', | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$InstallAccount | ||
) | ||
|
||
Write-Verbose -Message "Looking for SPWebApplication property '$Key'" | ||
|
||
$result = Invoke-SPDSCCommand -Credential $InstallAccount ` | ||
-Arguments $PSBoundParameters ` | ||
-ScriptBlock { | ||
$params = $args[0] | ||
|
||
$spWebApp = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue | ||
|
||
if ($null -eq $spWebApp) | ||
{ | ||
$currentValue = $null | ||
$localEnsure = 'Absent' | ||
} | ||
else | ||
{ | ||
if ($spWebApp.Properties) | ||
{ | ||
if ($spWebApp.Properties.Contains($params.Key) -eq $true) | ||
{ | ||
$localEnsure = "Present" | ||
$currentValue = $spWebApp.Properties[$params.Key] | ||
} | ||
else | ||
{ | ||
$localEnsure = "Absent" | ||
$currentValue = $null | ||
} | ||
} | ||
} | ||
|
||
return @{ | ||
WebAppUrl = $params.WebAppUrl | ||
Key = $params.Key | ||
Value = $currentValue | ||
Ensure = $localEnsure | ||
} | ||
} | ||
return $result | ||
} | ||
|
||
function Set-TargetResource() | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$WebAppUrl, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$Key, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$Value, | ||
|
||
[Parameter()] | ||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = 'Present', | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$InstallAccount | ||
) | ||
|
||
Write-Verbose -Message "Setting SPWebApplication property '$Key'" | ||
|
||
Invoke-SPDSCCommand -Credential $InstallAccount ` | ||
-Arguments $PSBoundParameters ` | ||
-ScriptBlock { | ||
$params = $args[0] | ||
|
||
$spWebApp = Get-SPWebApplication -Identity $params.WebAppUrl -ErrorAction SilentlyContinue | ||
|
||
if ($params.Ensure -eq 'Present') | ||
{ | ||
Write-Verbose -Message "Adding property '$($params.Key)'='$($params.value)' to SPWebApplication.Properties" | ||
$spWebApp.Properties[$params.Key] = $params.Value | ||
$spWebApp.Update() | ||
} | ||
else | ||
{ | ||
Write-Verbose -Message "Removing property '$($params.Key)' from SPWebApplication.Properties" | ||
$spWebApp.Properties.Remove($params.Key) | ||
$spWebApp.Update() | ||
} | ||
} | ||
} | ||
|
||
function Test-TargetResource() | ||
{ | ||
[CmdletBinding()] | ||
[OutputType([System.Boolean])] | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$WebAppUrl, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$Key, | ||
|
||
[Parameter()] | ||
[System.String] | ||
$Value, | ||
|
||
[Parameter()] | ||
[ValidateSet("Present","Absent")] | ||
[System.String] | ||
$Ensure = 'Present', | ||
|
||
[Parameter()] | ||
[System.Management.Automation.PSCredential] | ||
$InstallAccount | ||
) | ||
|
||
Write-Verbose -Message "Testing SPWebApplication property '$Key'" | ||
|
||
$CurrentValues = Get-TargetResource @PSBoundParameters | ||
|
||
if($Ensure -eq 'Present') | ||
{ | ||
return Test-SPDscParameterState -CurrentValues $CurrentValues ` | ||
-DesiredValues $PSBoundParameters ` | ||
-ValuesToCheck @('Ensure','Key', 'Value') | ||
} | ||
else | ||
{ | ||
return Test-SPDscParameterState -CurrentValues $CurrentValues ` | ||
-DesiredValues $PSBoundParameters ` | ||
-ValuesToCheck @('Ensure','Key') | ||
|
||
} | ||
|
||
} | ||
|
||
Export-ModuleMember -Function *-TargetResource |
9 changes: 9 additions & 0 deletions
9
...s/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/MSFT_SPWebAppPropertyBag.schema.mof
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,9 @@ | ||
[ClassVersion("1.0.0.0"), FriendlyName("SPWebAppPropertyBag")] | ||
class MSFT_SPWebAppPropertyBag : OMI_BaseResource | ||
{ | ||
[Key, Description("The URL of the web application")] string WebAppUrl; | ||
[Key, Description("The key of the SPWebApplication property")] string Key; | ||
[Write, Description("Value of the SPWebApplication property")] String Value; | ||
[Write, Description("Set to present to ensure the SPWebApplication property exists, or absent to ensure it is removed"), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] string Ensure; | ||
[Write, Description("POWERSHELL 4 ONLY: The account to run this resource as, use PsDscRunAsCredential if using PowerShell 5"), EmbeddedInstance("MSFT_Credential")] String InstallAccount; | ||
}; |
10 changes: 10 additions & 0 deletions
10
Modules/SharePointDsc/DSCResources/MSFT_SPWebAppPropertyBag/readme.md
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,10 @@ | ||
# Description | ||
|
||
**Type:** Distributed | ||
|
||
This resource is used to work with SharePoint Property Bags | ||
at the web application level. | ||
The account that runs this resource must be a farm administrator. | ||
|
||
The default value for the Ensure parameter is Present. When not specifying this | ||
parameter, the property bag is configured. |
28 changes: 28 additions & 0 deletions
28
Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/1-AddWebAppPropertyBag.ps1
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,28 @@ | ||
<# | ||
.EXAMPLE | ||
This example shows how add property bag value in a web application. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[PSCredential] | ||
$SetupAccount | ||
) | ||
|
||
Import-DscResource -ModuleName SharePointDsc | ||
|
||
node localhost | ||
{ | ||
SPWebAppPropertyBag APPLICATION_APPCodeProperty | ||
{ | ||
PsDscRunAsCredential = $SetupAccount | ||
WebAppUrl = "https://web.contoso.com" | ||
Key = "KeyToAdd" | ||
Value = "ValueToAddOrModify" | ||
Ensure = "Present" | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Modules/SharePointDsc/Examples/Resources/SPWebAppPropertyBag/2-RemoveWebAppPropertyBag.ps1
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,27 @@ | ||
<# | ||
.EXAMPLE | ||
This example shows how remove a property bag value in a web application. | ||
#> | ||
|
||
Configuration Example | ||
{ | ||
param | ||
( | ||
[Parameter(Mandatory = $true)] | ||
[PSCredential] | ||
$SetupAccount | ||
) | ||
|
||
Import-DscResource -ModuleName SharePointDsc | ||
|
||
node localhost | ||
{ | ||
SPWebAppPropertyBag APPLICATION_APPCodeProperty | ||
{ | ||
PsDscRunAsCredential = $SetupAccount | ||
WebAppUrl = "https://web.contoso.com" | ||
Key = "KeyToRemove" | ||
Ensure = "Absent" | ||
} | ||
} | ||
} |
Oops, something went wrong.