Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
一部抜き出し
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
You can’t perform that action at this time.