测试DSC定制资源

问题描述:

我在DSC定制资源的新。测试DSC定制资源

我创建1个自定义DSC资源投入C:\ Program Files文件\ WindowsPowerShell \模块路径的自定义资源的代码创建 文件低于

`

function Set-TargetResource 
{ 
    [CmdletBinding()] 
    param 
    (
     [parameter(Mandatory = $true)] 
     [System.String] 
     $ServerURL, 
     [parameter(Mandatory = $true)] 
     [System.String] 
     $ResultFilePath 
    ) 
    Try 
    { 
     $res=Get-WmiObject win32_service -ComputerName $ServerURL -Filter "Name = 'wuauserv'" 

     if($res.Status -eq "OK") 
     { 
      if((Test-Path $ResultFilePath)) 
      { 
       Out-File $ResultFilePath -InputObject "$ServerURL is Running" 
      } 
      else 
      { 
       New-Item -Path $ResultFilePath -ItemType file -Value "$ServerURL is Running" 
      } 
     } 
     else 
     { 
      if((Test-Path $ResultFilePath)) 
      { 
       Out-File $ResultFilePath -InputObject "$ServerURL is not Running" 
      } 
      else 
      { 
       New-Item -Path $ResultFilePath -ItemType file -Value "$ServerURL is not Running" 
      } 
     } 
    } 
    Catch 
    { 
      if((Test-Path $ResultFilePath)) 
      { 
       Out-File $ResultFilePath -InputObject "$ServerURL is not Running" 
      } 
      else 
      { 
       New-Item -Path $ResultFilePath -ItemType file -Value "$ServerURL is not Running" 
      } 
    } 

}

`

和DSC资源文件的使用率低于

Configuration ServerTest 
{ 

    param(
     [Parameter(Mandatory=$True,Position=0)] 
     $MachineName, 
     [Parameter(Mandatory=$True,Position=1)] 
     $ServerIPOrMachineName, 
     [Parameter(Mandatory=$True,Position=2)] 
     $ResultFilePath 


    ) 
    #param ($MachineName="localhost") 
    Try 
    { 
     Import-DscResource -ModuleName ServerStatusDSCmodule 
     node "localhost" 
     { 
      ServerStatusDSCResource MyServerTest 
      { 
       ServerURL = $ServerIPOrMachineName 
       ResultFilePath = $ResultFilePath 
      } 
     } 

    } 
    Catch 
    { 

    } 

} 
ServerTest 

这将创建Servertest文件夹,并localhost.mof但是当我运行启动DscConfiguration -Path “d:\ ServerTest \”它将无法创建文件给$ ResultFilePath

+0

你指定的参数ServerTest当你调用它(即所产生的MOF文件的步骤) –

我当Test函数返回false时发现我的错误,然后只设置函数调用,并且在我的Test函数中它总是返回true。