Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created May 12, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/1a6c194bbc76ef011db8 to your computer and use it in GitHub Desktop.
Save guitarrapc/1a6c194bbc76ef011db8 to your computer and use it in GitHub Desktop.
一部抜き出し
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