DSCResources/MSFT_SPVisioServiceApp/MSFT_SPVisioServiceApp.psm1
function Get-TargetResource { [CmdletBinding()] [OutputType([System.Collections.Hashtable])] param ( [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Getting Visio Graphics 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" } if ($null -eq $serviceApps) { return $nullReturn } $serviceApp = $serviceApps | Where-Object { $_.TypeName -eq "Visio Graphics Service Application" } if ($null -eq $serviceApp) { return $nullReturn } else { return @{ Name = $serviceApp.DisplayName ApplicationPool = $serviceApp.ApplicationPool.Name Ensure = "Present" InstallAccount = $params.InstallAccount } } } return $result } function Set-TargetResource { [CmdletBinding()] param ( [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [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 Visio Graphics Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] New-SPVisioServiceApplication -Name $params.Name ` -ApplicationPool $params.ApplicationPool } } if ($result.Ensure -eq "Present" -and $Ensure -eq "Present") { if ($ApplicationPool -ne $result.ApplicationPool) { Write-Verbose -Message "Updating Visio Graphics Service Application $Name" Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] $appPool = Get-SPServiceApplicationPool -Identity $params.ApplicationPool Get-SPServiceApplication -Name $params.Name ` | Where-Object { $_.TypeName -eq "Visio Graphics Service Application" } ` | Set-SPVisioServiceApplication -ServiceApplicationPool $appPool } } } if ($Ensure -eq "Absent") { Write-Verbose -Message "Removing Visio service application $Name" Invoke-SPDSCCommand -Credential $InstallAccount -Arguments $PSBoundParameters -ScriptBlock { $params = $args[0] $service = Get-SPServiceApplication -Name $params.Name ` | Where-Object { $_.TypeName -eq "Visio Graphics Service Application" } Remove-SPServiceApplication $service -Confirm:$false } } } function Test-TargetResource { [CmdletBinding()] [OutputType([System.Boolean])] param ( [parameter(Mandatory = $true)] [System.String] $Name, [parameter(Mandatory = $true)] [System.String] $ApplicationPool, [parameter(Mandatory = $false)] [ValidateSet("Present","Absent")] [System.String] $Ensure = "Present", [parameter(Mandatory = $false)] [System.Management.Automation.PSCredential] $InstallAccount ) Write-Verbose -Message "Testing for Visio Graphics Service Application '$Name'" $CurrentValues = Get-TargetResource @PSBoundParameters $PSBoundParameters.Ensure = $Ensure return Test-SPDSCSpecificParameters -CurrentValues $CurrentValues -DesiredValues $PSBoundParameters -ValuesToCheck @("ApplicationPool", "Ensure") } Export-ModuleMember -Function *-TargetResource |