I am new in DSC custom resources.
I created 1 custom dsc resource and put into C:\Program Files\WindowsPowerShell\Modules path file created for custom resource code is below
`
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"
}
}
}
`
And usage of DSC resource file is below
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
This will create Servertest folder and localhost.mof but when I run Start-DscConfiguration -Path "D:\ServerTest\" it will not able to create file given to $ResultFilePath