Would be great if I could use this resource to create new event logs and event sources.
For example today I would call New-EventLog like this to get this done:
### Create log and source
New-EventLog -LogName BigLog -Source TheHorsesMouth
My lame workaround is to use the Script resource:
Script MyEventLog
{
GetScript = {
return @{LogName='MyEventLog'}
}
TestScript = {
try{
Write-Verbose "Getting EventLog 'MyEventLog' with Source 'MySource'"
Get-EventLog -LogName MyEventLog -Source MySource -Newest 1 | Out-Null
return $true
}
catch{
Write-Warning 'Log not found'
return $false
}
}
SetScript = {
Write-Verbose "Creating EventLog 'MyEventLog' with Source 'MySource'"
New-EventLog -LogName MyEventLog -Source MySource -Verbose
}
}
Would be great if I could use this resource to create new event logs and event sources.
For example today I would call New-EventLog like this to get this done:
My lame workaround is to use the Script resource:
Script MyEventLog { GetScript = { return @{LogName='MyEventLog'} } TestScript = { try{ Write-Verbose "Getting EventLog 'MyEventLog' with Source 'MySource'" Get-EventLog -LogName MyEventLog -Source MySource -Newest 1 | Out-Null return $true } catch{ Write-Warning 'Log not found' return $false } } SetScript = { Write-Verbose "Creating EventLog 'MyEventLog' with Source 'MySource'" New-EventLog -LogName MyEventLog -Source MySource -Verbose } }