DSCResources/MSFT_SPAccessServiceApp/MSFT_SPAccessServiceApp.psm1
function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] param ( [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [parameter(Mandatory = $true)] [System.String] $DatabaseServer, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Getting Access Services service app '$Name'" $result = Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] $serviceApps = Get-SPServiceApplication -Name $params.Name -ErrorAction SilentlyContinue $nullReturn = @{ Name = $params.Name ApplicationPool = $params.ApplicationPool Ensure = "Absent" InstallAccount = $params.InstallAccount } if ($null -eq $serviceApps) { return $nullReturn } $serviceApp = $serviceApps | Where-Object { $_.TypeName -eq "Access Services Web Service Application" } If ($null -eq $serviceApp) { return $nullReturn } else { return @{ Name = $serviceApp.DisplayName ApplicationPool = $serviceApp.ApplicationPool.Name Ensure = "Present" } } } return $result } function Set-TargetResource { [CmdletBinding()] param ( [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [parameter(Mandatory = $true)] [System.String] $DatabaseServer, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount ) $result = Get-TargetResource @PSBoundParameters if ($result.Ensure -eq "Absent" -and $Ensure -eq "Present") { Write-Verbose -Message "Creating Access Services Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] $app = New-SPAccessServicesApplication -Name $params.Name ` -ApplicationPool $params.ApplicationPool ` -Default ` -DatabaseServer $params.DatabaseServer $app | New-SPAccessServicesApplicationProxy | Out-Null } } if ($Ensure -eq "Absent") { Write-Verbose -Message "Removing Access Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] $appService = Get-SPServiceApplication -Name $params.Name | Where-Object { $_.TypeName -eq "Access Services Web Service Application" } Remove-SPServiceApplication $appService -Confirm:$false } } } function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] param ( [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [parameter(Mandatory = $true)] [System.String] $DatabaseServer, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount ) $PSBoundParameters.Ensure = $Ensure Write-Verbose -Message "Testing for Access Service Application '$Name'" $CurrentValues = Get-TargetResource @PSBoundParameters return Test-SPDSCSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("Ensure") } Export-ModuleMember -Function *-TargetResource |