我不了解如何创建所需状态配置资源的概念。我不断收到错误。我使用以下。有人可以给我一个非常简单的方法来理解这一点吗?
财政部
[ClassVersion("1.0.0"), FriendlyName("SQLInstall")]
class MSFT_SQLInstall: OMI_BaseResource
{
[Key] String InstanceName;
[Write] String SA;
[Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
};
PSM1:
Function Get-TargetResource
{
param(
[parameter(Mandatory = $true)]
[System.String]
$InstanceName,
[ValidateSet('Present','Absent')]
[System.String]
$Ensure )
$ins = @($InstanceName)
return $ins
}
Function Set-TargetResource
{
param(
[parameter(Mandatory = $true)]
[System.String]
$InstanceName,
[ValidateSet('Present','Absent')]
[System.String]
$Ensure )
}
function Test-TargetResource
{
[OutputType([System.Boolean])]
param
(
[parameter(Mandatory = $true)]
[System.String]
$InstanceName,
[ValidateSet('Present','Absent')]
[System.String]
$Ensure
)
try {
write-verbose "Test: Getting current Instance $Instance status"
$Status = <# test goes here #>
if ($Ensure -like 'Present')
{
if (($Status -eq $true))
{
return $true
}
else
{
return $false
}
}
else
{
if ($Status -eq $true)
{
return $false
}
else
{
return $true
}
}
}
Catch {
$exception = $_
Write-Verbose ("An Error Occurred: $exception.message")
}
}