Created
May 12, 2015 16:17
-
-
Save guitarrapc/1a6c194bbc76ef011db8 to your computer and use it in GitHub Desktop.
一部抜き出し
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
function Get-TargetResource | |
{ | |
[CmdletBinding()] | |
[OutputType([System.Collections.Hashtable])] | |
param | |
( | |
[parameter(Mandatory = $true)] | |
[System.String]$Path, | |
[parameter(Mandatory = $true)] | |
[System.String]$ServiceName, | |
[parameter(Mandatory = $true)] | |
[ValidateSet("Present","Absent")] | |
[System.String]$Ensure | |
) | |
# validate path is correct. | |
ValidatePathExists -Path $Path | |
# Check existing is TopShelfService or not | |
if (-not (IsServiceExists -Name $ServiceName)) | |
{ | |
Write-Debug $debugMessages.ServiceNotExists | |
$ensureResult = [EnsureType]::Absent.ToString() | |
} | |
else | |
{ | |
# service exist. Validate if it is TopShelf Service or not | |
if (IsTopShelfService -Name $ServiceName -Path $Path) | |
{ | |
$ensureResult = [EnsureType]::Present.ToString() | |
} | |
else | |
{ | |
$ensureResult = [EnsureType]::Absent.ToString() | |
} | |
} | |
$returnValue = @{ | |
Path = $Path | |
ServiceName = $ServiceName | |
Ensure = $ensureResult | |
} | |
return $returnValue | |
} | |
function Set-TargetResource | |
{ | |
[CmdletBinding()] | |
param | |
( | |
[parameter(Mandatory = $true)] | |
[System.String]$Path, | |
[parameter(Mandatory = $true)] | |
[System.String]$ServiceName, | |
[parameter(Mandatory = $true)] | |
[ValidateSet("Present","Absent")] | |
[System.String]$Ensure | |
) | |
if ($Ensure -eq [EnsureType]::Absent.ToString()) | |
{ | |
UninstallTopShelfService -Path $Path | |
return; | |
} | |
InstallTopShelfService -Path $Path | |
} | |
function Test-TargetResource | |
{ | |
[CmdletBinding()] | |
[OutputType([System.Boolean])] | |
param | |
( | |
[parameter(Mandatory = $true)] | |
[System.String]$Path, | |
[parameter(Mandatory = $true)] | |
[System.String]$ServiceName, | |
[parameter(Mandatory = $true)] | |
[ValidateSet("Present","Absent")] | |
[System.String]$Ensure | |
) | |
$result = (Get-TargetResource -Path $Path -ServiceName $ServiceName -Ensure $Ensure).Ensure -eq $Ensure | |
return $result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment