0
我在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
你指定的參數ServerTest當你調用它(即所產生的MOF文件的步驟) –