2

PowerShell で DSC を使用してサービスを展開しようとしています。Microsoft Documentationによると、サービス リソースには次の設定可能なプロパティがあります。

  • 名前
  • 確認
  • ビルトインアカウント
  • 資格情報
  • 依存関係
  • 引数
  • スタートアップの種類

DSC 構成でサービスを定義しましたが、エラーが発生します。

これは私のコードです:

Configuration ServiceDeployConfig
{
param(
    [string[]]$ComputerName="localhost",

    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $serviceDeployPath,

    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $serviceName,

    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $serviceDisplayName,

    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $serviceExecutable,

    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $serviceUserame,

    [Parameter(Mandatory)]
    [ValidateNotNullOrEmpty()]
    [string] $servicePassword
)

Node $ComputerName
{
    File serviceFiles
    {
        Ensure = "Present"
        SourcePath = "\\Path\to\exe\$serviceExecutable"
        DestinationPath = $serviceDeployPath

    }

    Service serviceInstall 
    {
        Ensure = "Present"
        Name = $serviceName
        Credential = New-Object System.Management.Automation.PSCredential ($serviceUserame, (ConvertTo-SecureString $servicePassword -AsPlainText -Force))
        DependsOn = "[File]serviceFiles"
        Arguments = "-binaryPathName $serviceDeployPath\$serviceExecutable", "-displayName $serviceDisplayName"
        StartupType = Automatic
        Status = Start
    }

}
}

ここに私が得るエラーがあります:

At line:43 char:13
+             Ensure = "Present"
+             ~~~~~~
The member 'Ensure' is not valid. Valid members are 'DependsOn', 'Name', 'State', 'StartupType', 'BuiltInAccount', 'Credential'. Please update your script and try again.
At line:47 char:13
+             Arguments = "-binaryPathName $serviceDeployPath\$serviceExecutable", ...
+             ~~~~~~~~~
The member 'Arguments' is not valid. Valid members are 'DependsOn', 'Name', 'State', 'StartupType', 'BuiltInAccount', 'Credential'. Please update your script and try again.
At line:49 char:13
+             Status = Start
+             ~~~~~~
The member 'Status' is not valid. Valid members are 'DependsOn', 'Name', 'State', 'StartupType', 'BuiltInAccount', 'Credential'. Please update your script and try again.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidInstanceProperty

私は GitHub ( https://gist.github.com/grenade/7677021 ) でこの例をたどったので、自分のコードに関して正しい道をたどっていることがわかります。

ダウンロードする必要がある新しいバージョンの DSC はありますか? ドキュメントリストにあるが存在しないように見えるプロパティを使用するときに、どのように機能させるのですか?

4

3 に答える 3

4

Bartek が指摘するように、ドキュメントにはバグがあります! DSC 関連の開発がすべて終了したら、更新があると思います。PowerShell 4.0 のリリース以来、ほぼ毎月変更されています。:)

確認プロパティに関するいくつかの補足事項:

プロパティは、Ensure構成エンティティを「作成」する必要があるシナリオで使用されます。たとえば、機能がインストールされていることを「確認」します。つまり、まだインストールされていない場合はインストールします。

Ensureプロパティは、組み込みのサービス リソースでは意味がありません。彼らはサービスを作成していません。彼らは、サービスが特定の状態にあるかどうかやその他の設定のみを調べています。したがって、ensure プロパティを使用すると、常に現在のサービス構成の状態を確認し、必要に応じて新しい構成を適用できます。

プロパティを使用してサービスを作成できるxServiceリソースがありEnsureます。

于 2014-05-28T06:24:53.350 に答える
1

MSDN のドキュメントと例の両方が正しくないようです。ボックスをチェックしても、このリソースの確認/引数/ステータスが表示されません。

Get-DscResourceコマンドレットを使用して、システムで使用可能なプロパティを確認できます。

Get-DscResource -Name Service | ForEach-Object Properties

接続ページのドキュメント バグとして報告することをお勧めします (まだ表示されていない場合)。

于 2014-05-27T13:43:29.987 に答える